Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pacman: use embed function #1710

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions completers/pacman_completer/cmd/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ import (
"github.com/spf13/cobra"
)

func initDatabaseCmd(cmd *cobra.Command) {
cmd.Flags().String("arch", "", "set an alternate architecture")
cmd.Flags().Bool("asdeps", false, "mark packages as non-explicitly installed")
cmd.Flags().Bool("asexplicit", false, "mark packages as explicitly installed")
cmd.Flags().String("cachedir", "", "set an alternate package cache location")
cmd.Flags().CountP("check", "k", "test local database for validity (-kk for sync databases)")
cmd.Flags().String("color", "", "colorize the output")
cmd.Flags().String("config", "", "set an alternate configuration file")
cmd.Flags().Bool("confirm", false, "always ask for confirmation")
cmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
cmd.Flags().Bool("debug", false, "display debug messages")
cmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
cmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
cmd.Flags().String("hookdir", "", "set an alternate hook location")
cmd.Flags().String("logfile", "", "set an alternate log file")
cmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
cmd.Flags().BoolP("quiet", "q", false, "suppress output of success messages")
cmd.Flags().StringP("root", "r", "", "set an alternate installation root")
cmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
cmd.Flags().BoolP("verbose", "v", false, "be verbose")
var databaseCmd = &cobra.Command{
Use: "database",
Aliases: []string{"D"},
Short: "Operate on the package database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
databaseCmd.Flags().String("arch", "", "set an alternate architecture")
databaseCmd.Flags().Bool("asdeps", false, "mark packages as non-explicitly installed")
databaseCmd.Flags().Bool("asexplicit", false, "mark packages as explicitly installed")
databaseCmd.Flags().String("cachedir", "", "set an alternate package cache location")
databaseCmd.Flags().CountP("check", "k", "test local database for validity (-kk for sync databases)")
databaseCmd.Flags().String("color", "", "colorize the output")
databaseCmd.Flags().String("config", "", "set an alternate configuration file")
databaseCmd.Flags().Bool("confirm", false, "always ask for confirmation")
databaseCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
databaseCmd.Flags().Bool("debug", false, "display debug messages")
databaseCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
databaseCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
databaseCmd.Flags().String("hookdir", "", "set an alternate hook location")
databaseCmd.Flags().String("logfile", "", "set an alternate log file")
databaseCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
databaseCmd.Flags().BoolP("quiet", "q", false, "suppress output of success messages")
databaseCmd.Flags().StringP("root", "r", "", "set an alternate installation root")
databaseCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
databaseCmd.Flags().BoolP("verbose", "v", false, "be verbose")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
carapace.Gen(databaseCmd).FlagCompletion(carapace.ActionMap{
"arch": carapace.ActionValues("i686", "x86_64"),
"cachedir": carapace.ActionDirectories(),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
Expand All @@ -40,7 +47,7 @@ func initDatabaseCmd(cmd *cobra.Command) {
"root": carapace.ActionDirectories(),
})

carapace.Gen(cmd).PositionalAnyCompletion(
carapace.Gen(databaseCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA()
}),
Expand Down
43 changes: 25 additions & 18 deletions completers/pacman_completer/cmd/deptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@ import (
"github.com/spf13/cobra"
)

func initDeptestCmd(cmd *cobra.Command) {
cmd.Flags().String("arch", "", "set an alternate architecture")
cmd.Flags().String("cachedir", "", "set an alternate package cache location")
cmd.Flags().String("color", "", "colorize the output")
cmd.Flags().String("config", "", "set an alternate configuration file")
cmd.Flags().Bool("confirm", false, "always ask for confirmation")
cmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
cmd.Flags().Bool("debug", false, "display debug messages")
cmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
cmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
cmd.Flags().String("hookdir", "", "set an alternate hook location")
cmd.Flags().String("logfile", "", "set an alternate log file")
cmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
cmd.Flags().StringP("root", "r", "", "set an alternate installation root")
cmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
cmd.Flags().BoolP("verbose", "v", false, "be verbose")
var deptestCmd = &cobra.Command{
Use: "deptest",
Aliases: []string{"T"},
Short: "Operate on the package database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
deptestCmd.Flags().String("arch", "", "set an alternate architecture")
deptestCmd.Flags().String("cachedir", "", "set an alternate package cache location")
deptestCmd.Flags().String("color", "", "colorize the output")
deptestCmd.Flags().String("config", "", "set an alternate configuration file")
deptestCmd.Flags().Bool("confirm", false, "always ask for confirmation")
deptestCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
deptestCmd.Flags().Bool("debug", false, "display debug messages")
deptestCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
deptestCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
deptestCmd.Flags().String("hookdir", "", "set an alternate hook location")
deptestCmd.Flags().String("logfile", "", "set an alternate log file")
deptestCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
deptestCmd.Flags().StringP("root", "r", "", "set an alternate installation root")
deptestCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
deptestCmd.Flags().BoolP("verbose", "v", false, "be verbose")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
carapace.Gen(deptestCmd).FlagCompletion(carapace.ActionMap{
"arch": carapace.ActionValues("i686", "x86_64"),
"cachedir": carapace.ActionDirectories(),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
Expand All @@ -36,7 +43,7 @@ func initDeptestCmd(cmd *cobra.Command) {
"root": carapace.ActionDirectories(),
})

carapace.Gen(cmd).PositionalAnyCompletion(
carapace.Gen(deptestCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA()
}),
Expand Down
53 changes: 30 additions & 23 deletions completers/pacman_completer/cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,36 @@ import (
"github.com/spf13/cobra"
)

func initFilesCmd(cmd *cobra.Command) {
cmd.Flags().String("arch", "", "set an alternate architecture")
cmd.Flags().String("cachedir", "", "set an alternate package cache location")
cmd.Flags().String("color", "", "colorize the output")
cmd.Flags().String("config", "", "set an alternate configuration file")
cmd.Flags().Bool("confirm", false, "always ask for confirmation")
cmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
cmd.Flags().Bool("debug", false, "display debug messages")
cmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
cmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
cmd.Flags().String("hookdir", "", "set an alternate hook location")
cmd.Flags().BoolP("list", "l", false, "list the files owned by the queried package")
cmd.Flags().String("logfile", "", "set an alternate log file")
cmd.Flags().Bool("machinereadable", false, "produce machine-readable output")
cmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
cmd.Flags().BoolP("quiet", "q", false, "show less information for query and search")
cmd.Flags().CountP("refresh", "y", "download fresh package databases from the server")
cmd.Flags().BoolP("regex", "x", false, "enable searching using regular expressions")
cmd.Flags().StringP("root", "r", "", "set an alternate installation root")
cmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
cmd.Flags().BoolP("verbose", "v", false, "be verbose")
var filesCmd = &cobra.Command{
Use: "files",
Aliases: []string{"F"},
Short: "Query the files database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
filesCmd.Flags().String("arch", "", "set an alternate architecture")
filesCmd.Flags().String("cachedir", "", "set an alternate package cache location")
filesCmd.Flags().String("color", "", "colorize the output")
filesCmd.Flags().String("config", "", "set an alternate configuration file")
filesCmd.Flags().Bool("confirm", false, "always ask for confirmation")
filesCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
filesCmd.Flags().Bool("debug", false, "display debug messages")
filesCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
filesCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
filesCmd.Flags().String("hookdir", "", "set an alternate hook location")
filesCmd.Flags().BoolP("list", "l", false, "list the files owned by the queried package")
filesCmd.Flags().String("logfile", "", "set an alternate log file")
filesCmd.Flags().Bool("machinereadable", false, "produce machine-readable output")
filesCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
filesCmd.Flags().BoolP("quiet", "q", false, "show less information for query and search")
filesCmd.Flags().CountP("refresh", "y", "download fresh package databases from the server")
filesCmd.Flags().BoolP("regex", "x", false, "enable searching using regular expressions")
filesCmd.Flags().StringP("root", "r", "", "set an alternate installation root")
filesCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
filesCmd.Flags().BoolP("verbose", "v", false, "be verbose")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
carapace.Gen(filesCmd).FlagCompletion(carapace.ActionMap{
"arch": carapace.ActionValues("i686", "x86_64"),
"cachedir": carapace.ActionDirectories(),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
Expand All @@ -41,7 +48,7 @@ func initFilesCmd(cmd *cobra.Command) {
"root": carapace.ActionDirectories(),
})

carapace.Gen(cmd).PositionalAnyCompletion(
carapace.Gen(filesCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA()
}),
Expand Down
75 changes: 41 additions & 34 deletions completers/pacman_completer/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,46 @@ import (
"github.com/spf13/cobra"
)

func initQueryCmd(cmd *cobra.Command) {
cmd.Flags().String("arch", "", "set an alternate architecture")
cmd.Flags().String("cachedir", "", "set an alternate package cache location")
cmd.Flags().BoolP("changelog", "c", false, "view the changelog of a package")
cmd.Flags().CountP("check", "k", "check that package files exist (-kk for file properties)")
cmd.Flags().String("color", "", "colorize the output")
cmd.Flags().String("config", "", "set an alternate configuration file")
cmd.Flags().Bool("confirm", false, "always ask for confirmation")
cmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
cmd.Flags().Bool("debug", false, "display debug messages")
cmd.Flags().BoolP("deps", "d", false, "list packages installed as dependencies [filter]")
cmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
cmd.Flags().BoolP("explicit", "e", false, "list packages explicitly installed [filter]")
cmd.Flags().StringP("file", "p", "", "query a package file instead of the database")
cmd.Flags().BoolP("foreign", "m", false, "list installed packages not found in sync db(s) [filter]")
cmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
cmd.Flags().BoolP("groups", "g", false, "view all members of a package group")
cmd.Flags().String("hookdir", "", "set an alternate hook location")
cmd.Flags().CountP("info", "i", "view package information (-ii for backup files)")
cmd.Flags().BoolP("list", "l", false, "list the files owned by the queried package")
cmd.Flags().String("logfile", "", "set an alternate log file")
cmd.Flags().BoolP("native", "n", false, "list installed packages only found in sync db(s) [filter]")
cmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
cmd.Flags().StringP("owns", "o", "", "query the package that owns <file>")
cmd.Flags().BoolP("quiet", "q", false, "show less information for query and search")
cmd.Flags().StringP("root", "r", "", "set an alternate installation root")
cmd.Flags().StringP("search", "s", "", "search locally-installed packages for matching strings")
cmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
cmd.Flags().CountP("unrequired", "t", "list packages not (optionally) required by any package")
cmd.Flags().BoolP("upgrades", "u", false, "list outdated packages [filter]")
cmd.Flags().BoolP("verbose", "v", false, "be verbose")
var queryCmd = &cobra.Command{
Use: "query",
Aliases: []string{"Q"},
Short: "Query the package database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
queryCmd.Flags().String("arch", "", "set an alternate architecture")
queryCmd.Flags().String("cachedir", "", "set an alternate package cache location")
queryCmd.Flags().BoolP("changelog", "c", false, "view the changelog of a package")
queryCmd.Flags().CountP("check", "k", "check that package files exist (-kk for file properties)")
queryCmd.Flags().String("color", "", "colorize the output")
queryCmd.Flags().String("config", "", "set an alternate configuration file")
queryCmd.Flags().Bool("confirm", false, "always ask for confirmation")
queryCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location")
queryCmd.Flags().Bool("debug", false, "display debug messages")
queryCmd.Flags().BoolP("deps", "d", false, "list packages installed as dependencies [filter]")
queryCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download")
queryCmd.Flags().BoolP("explicit", "e", false, "list packages explicitly installed [filter]")
queryCmd.Flags().StringP("file", "p", "", "query a package file instead of the database")
queryCmd.Flags().BoolP("foreign", "m", false, "list installed packages not found in sync db(s) [filter]")
queryCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG")
queryCmd.Flags().BoolP("groups", "g", false, "view all members of a package group")
queryCmd.Flags().String("hookdir", "", "set an alternate hook location")
queryCmd.Flags().CountP("info", "i", "view package information (-ii for backup files)")
queryCmd.Flags().BoolP("list", "l", false, "list the files owned by the queried package")
queryCmd.Flags().String("logfile", "", "set an alternate log file")
queryCmd.Flags().BoolP("native", "n", false, "list installed packages only found in sync db(s) [filter]")
queryCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation")
queryCmd.Flags().StringP("owns", "o", "", "query the package that owns <file>")
queryCmd.Flags().BoolP("quiet", "q", false, "show less information for query and search")
queryCmd.Flags().StringP("root", "r", "", "set an alternate installation root")
queryCmd.Flags().StringP("search", "s", "", "search locally-installed packages for matching strings")
queryCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)")
queryCmd.Flags().CountP("unrequired", "t", "list packages not (optionally) required by any package")
queryCmd.Flags().BoolP("upgrades", "u", false, "list outdated packages [filter]")
queryCmd.Flags().BoolP("verbose", "v", false, "be verbose")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
carapace.Gen(queryCmd).FlagCompletion(carapace.ActionMap{
"arch": carapace.ActionValues("i686", "x86_64"),
"cachedir": carapace.ActionDirectories(),
"color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
Expand All @@ -53,9 +60,9 @@ func initQueryCmd(cmd *cobra.Command) {
"root": carapace.ActionDirectories(),
})

carapace.Gen(cmd).PositionalAnyCompletion(
carapace.Gen(queryCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if cmd.Flag("file").Changed {
if queryCmd.Flag("file").Changed {
return carapace.ActionFiles()
}
return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA()
Expand Down
Loading