diff --git a/apac b/apac new file mode 100755 index 0000000..999646a Binary files /dev/null and b/apac differ diff --git a/cmd/install.go b/cmd/install.go new file mode 100644 index 0000000..4cf813a --- /dev/null +++ b/cmd/install.go @@ -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) +} + diff --git a/cmd/root.go b/cmd/root.go index 54d2c6f..bc7f2d4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) { }, diff --git a/cmd/uninstall.go b/cmd/uninstall.go new file mode 100644 index 0000000..0d6bf86 --- /dev/null +++ b/cmd/uninstall.go @@ -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) +} + diff --git a/go.mod b/go.mod index 54c4e35..3d8bc7e 100644 --- a/go.mod +++ b/go.mod @@ -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 )