wrote source code
This commit is contained in:
@@ -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
@@ -15,13 +15,8 @@ import (
|
|||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "apac",
|
Use: "apac",
|
||||||
Short: "A brief description of your application",
|
Short: "Simple arch aur helper.",
|
||||||
Long: `A longer description that spans multiple lines and likely contains
|
Long: `Simple aur arch helper. It can manage packages for you`,
|
||||||
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.`,
|
|
||||||
// Uncomment the following line if your bare application
|
// Uncomment the following line if your bare application
|
||||||
// has an action associated with it:
|
// has an action associated with it:
|
||||||
// Run: func(cmd *cobra.Command, args []string) { },
|
// Run: func(cmd *cobra.Command, args []string) { },
|
||||||
|
|||||||
@@ -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,8 +2,9 @@ module apac
|
|||||||
|
|
||||||
go 1.26.2
|
go 1.26.2
|
||||||
|
|
||||||
|
require github.com/spf13/cobra v1.10.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/spf13/cobra v1.10.2 // indirect
|
|
||||||
github.com/spf13/pflag v1.0.9 // indirect
|
github.com/spf13/pflag v1.0.9 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user