Skip to content

Commit 8ed038a

Browse files
committed
Add xbps-remove completer
1 parent 5e9eabe commit 8ed038a

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cmd
2+
3+
import (
4+
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/xbps"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var rootCmd = &cobra.Command{
10+
Use: "xbps-remove [OPTIONS] [PKGNAME...]",
11+
Short: "XBPS utility to remove packages",
12+
Run: func(cmd *cobra.Command, args []string) {},
13+
}
14+
15+
func Execute() error {
16+
return rootCmd.Execute()
17+
}
18+
func init() {
19+
carapace.Gen(rootCmd).Standalone()
20+
21+
rootCmd.Flags().StringP("config", "C", "", "Path to confdir (xbps.d)")
22+
rootCmd.Flags().StringP("cachedir", "c", "", "Path to cachedir")
23+
rootCmd.Flags().BoolP("debug", "d", false, "Debug mode shown to stderr")
24+
rootCmd.Flags().BoolP("force-revdeps", "F", false, "Force package removal even with revdeps or unresolved shared libraries")
25+
rootCmd.Flags().BoolP("force", "f", false, "Force package re-installation. If specified twice, all files will be overwritten.")
26+
rootCmd.Flags().BoolP("help", "h", false, "Show usage")
27+
rootCmd.Flags().BoolP("dry-run", "n", false, "Dry-run mode")
28+
rootCmd.Flags().BoolP("clean-cache", "O", false, "Remove outdated packages from the cache. If specified twice, also remove uninstalled packages")
29+
rootCmd.Flags().BoolP("remove-orphans", "o", false, "Remove package orphans")
30+
rootCmd.Flags().BoolP("recursive", "R", false, "Recursively remove dependencies")
31+
rootCmd.Flags().StringP("rootdir", "r", "", "Full path to rootdir")
32+
rootCmd.Flags().BoolP("verbose", "v", false, "Verbose messages")
33+
rootCmd.Flags().BoolP("yes", "y", false, "Assume yes to all questions")
34+
rootCmd.Flags().BoolP("version", "V", false, "Show XBPS version")
35+
36+
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
37+
"config": carapace.ActionDirectories(),
38+
"cachedir": carapace.ActionDirectories(),
39+
"rootdir": carapace.ActionDirectories(),
40+
})
41+
carapace.Gen(rootCmd).PositionalAnyCompletion(xbps.ActionPackages().FilterArgs())
42+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/carapace-sh/carapace-bin/completers/common/xbps-remove_completer/cmd"
4+
5+
func main() {
6+
cmd.Execute()
7+
}

pkg/actions/tools/xbps/xbps.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ import (
88
"github.com/carapace-sh/carapace"
99
)
1010

11+
// ActionPackageSearch completes installed packages
12+
func ActionPackages() carapace.Action {
13+
re := regexp.MustCompile(`\S+\s(\S+)-\S+\s+(.*)`)
14+
15+
return carapace.ActionExecCommand("xbps-query", "-l")(func(output []byte) carapace.Action {
16+
lines := strings.Split(string(output), "\n")
17+
vals := make([]string, 0)
18+
19+
for _, line := range lines {
20+
match := re.FindStringSubmatch(line)
21+
22+
if len(match) > 1 {
23+
vals = append(vals, match[1], match[2])
24+
}
25+
}
26+
return carapace.ActionValuesDescribed(vals...)
27+
})
28+
}
29+
1130
// ActionPackageSearch completes installable packages
1231
func ActionPackageSearch() carapace.Action {
1332
re := regexp.MustCompile(`\[.\] (\S+)-\S+\s+(.*)`)

0 commit comments

Comments
 (0)