wrote source code

This commit is contained in:
2026-05-02 00:19:07 +02:00
parent ef7a4a8c45
commit 1dd20f169f
5 changed files with 93 additions and 8 deletions
Executable
BIN
View File
Binary file not shown.
+51
View File
@@ -0,0 +1,51 @@
package cmd
import (
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
var installCmd = &cobra.Command{
Use: "install",
Short: "installs a package",
Long: `installs a package from the aur to the system.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "error: package name required")
return
}
pkg := args[0]
url := "https://aur.archlinux.org/" + pkg
// git clone
fmt.Println("cloning:", url)
out, err := exec.Command("git", "clone", url).CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "git clone failed: %v\n%s\n", err, string(out))
return
}
// makepkg -si inside package dir
fmt.Println("building/installing:", pkg)
buildCmd := exec.Command("makepkg", "-si", "--noconfirm")
buildCmd.Dir = pkg
buildCmd.Stdin = os.Stdin
buildCmd.Stdout = os.Stdout
buildCmd.Stderr = os.Stderr
buildCmd.Run()
// cleanup
if err := os.RemoveAll(pkg); err != nil {
fmt.Fprintf(os.Stderr, "warning: failed to remove %s: %v\n", pkg, err)
}
fmt.Println("install successful")
},
}
func init() {
rootCmd.AddCommand(installCmd)
}
+2 -7
View File
@@ -15,13 +15,8 @@ import (
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "apac",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Short: "Simple arch aur helper.",
Long: `Simple aur arch helper. It can manage packages for you`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
+38
View File
@@ -0,0 +1,38 @@
package cmd
import (
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
// uninstallCmd represents the uninstall command
var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "uninstalls a package",
Long: `Uninstalls a package.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "error: package name required")
return
}
pkg := args[0]
// Ensure running as root (pacman requires root)
fmt.Println("uninstalling:", pkg)
out := exec.Command("sudo", "pacman", "-R", pkg)
out.Stdin =os.Stdin
out.Stdout =os.Stdout
out.Stderr =os.Stderr
out.Run()
fmt.Println("uninstall successful")
},
}
func init() {
rootCmd.AddCommand(uninstallCmd)
}
+2 -1
View File
@@ -2,8 +2,9 @@ module apac
go 1.26.2
require github.com/spf13/cobra v1.10.2
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.9 // indirect
)