From abd5c41dfbfb6cf34c2eb31c2ef29bfcb5af6820 Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 27 Jun 2023 17:30:41 +0200 Subject: [PATCH] added yay --- completers/pacman_completer/cmd/upgrade.go | 2 +- completers/yay_completer/cmd/build.go | 21 ++++++ completers/yay_completer/cmd/database.go | 57 ++++++++++++++ completers/yay_completer/cmd/deptest.go | 53 +++++++++++++ completers/yay_completer/cmd/files.go | 58 ++++++++++++++ completers/yay_completer/cmd/getpkgbuild.go | 27 +++++++ completers/yay_completer/cmd/query.go | 73 ++++++++++++++++++ completers/yay_completer/cmd/remove.go | 64 ++++++++++++++++ completers/yay_completer/cmd/root.go | 44 +++++++++++ completers/yay_completer/cmd/show.go | 23 ++++++ completers/yay_completer/cmd/sync.go | 84 +++++++++++++++++++++ completers/yay_completer/cmd/upgrade.go | 72 ++++++++++++++++++ completers/yay_completer/cmd/web.go | 24 ++++++ completers/yay_completer/cmd/yay.go | 27 +++++++ completers/yay_completer/main.go | 7 ++ pkg/util/embed/flag.go | 51 +++++++++++++ 16 files changed, 686 insertions(+), 1 deletion(-) create mode 100644 completers/yay_completer/cmd/build.go create mode 100644 completers/yay_completer/cmd/database.go create mode 100644 completers/yay_completer/cmd/deptest.go create mode 100644 completers/yay_completer/cmd/files.go create mode 100644 completers/yay_completer/cmd/getpkgbuild.go create mode 100644 completers/yay_completer/cmd/query.go create mode 100644 completers/yay_completer/cmd/remove.go create mode 100644 completers/yay_completer/cmd/root.go create mode 100644 completers/yay_completer/cmd/show.go create mode 100644 completers/yay_completer/cmd/sync.go create mode 100644 completers/yay_completer/cmd/upgrade.go create mode 100644 completers/yay_completer/cmd/web.go create mode 100644 completers/yay_completer/cmd/yay.go create mode 100644 completers/yay_completer/main.go create mode 100644 pkg/util/embed/flag.go diff --git a/completers/pacman_completer/cmd/upgrade.go b/completers/pacman_completer/cmd/upgrade.go index 66419483a3..811be565e2 100644 --- a/completers/pacman_completer/cmd/upgrade.go +++ b/completers/pacman_completer/cmd/upgrade.go @@ -40,7 +40,7 @@ func initUpgradeCmd(cmd *cobra.Command) { carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{ "arch": carapace.ActionValues("i686", "x86_64"), - "cache-dir": carapace.ActionDirectories(), + "cachedir": carapace.ActionDirectories(), "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), "config": carapace.ActionFiles(), "dbpath": carapace.ActionFiles(), diff --git a/completers/yay_completer/cmd/build.go b/completers/yay_completer/cmd/build.go new file mode 100644 index 0000000000..0cbd0e7e1a --- /dev/null +++ b/completers/yay_completer/cmd/build.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var buildCmd = &cobra.Command{ + Use: "build", + Aliases: []string{"B"}, + Short: "", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(buildCmd).Standalone() + + carapace.Gen(buildCmd).PositionalCompletion( + carapace.ActionDirectories(), + ) +} diff --git a/completers/yay_completer/cmd/database.go b/completers/yay_completer/cmd/database.go new file mode 100644 index 0000000000..49dd8d6115 --- /dev/null +++ b/completers/yay_completer/cmd/database.go @@ -0,0 +1,57 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var databaseCmd = &cobra.Command{ + Use: "database", + Aliases: []string{"D"}, + Short: "Operate on the package database", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(databaseCmd).Standalone() + + 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(databaseCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + "logfile": carapace.ActionFiles(), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(databaseCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/deptest.go b/completers/yay_completer/cmd/deptest.go new file mode 100644 index 0000000000..8aa3213d66 --- /dev/null +++ b/completers/yay_completer/cmd/deptest.go @@ -0,0 +1,53 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var deptestCmd = &cobra.Command{ + Use: "deptest", + Aliases: []string{"T"}, + Short: "Check dependencies", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(deptestCmd).Standalone() + + 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(deptestCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + "logfile": carapace.ActionFiles(), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(deptestCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/files.go b/completers/yay_completer/cmd/files.go new file mode 100644 index 0000000000..0428d05f89 --- /dev/null +++ b/completers/yay_completer/cmd/files.go @@ -0,0 +1,58 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var filesCmd = &cobra.Command{ + Use: "files", + Aliases: []string{"F"}, + Short: "Query the files database", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(filesCmd).Standalone() + + 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(filesCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + "logfile": carapace.ActionFiles(), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(filesCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/getpkgbuild.go b/completers/yay_completer/cmd/getpkgbuild.go new file mode 100644 index 0000000000..5825616cd7 --- /dev/null +++ b/completers/yay_completer/cmd/getpkgbuild.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/spf13/cobra" +) + +var getpkgbuildCmd = &cobra.Command{ + Use: "getpkgbuild", + Aliases: []string{"G"}, + Short: "", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(getpkgbuildCmd).Standalone() + + getpkgbuildCmd.Flags().BoolP("-f", "--force", false, "Force download for existing ABS packages") + getpkgbuildCmd.Flags().BoolP("-p", "--print", false, "Print pkgbuild of packages") + + carapace.Gen(getpkgbuildCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/query.go b/completers/yay_completer/cmd/query.go new file mode 100644 index 0000000000..aea49d5165 --- /dev/null +++ b/completers/yay_completer/cmd/query.go @@ -0,0 +1,73 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var queryCmd = &cobra.Command{ + Use: "query", + Aliases: []string{"Q"}, + Short: "Query the package database", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(queryCmd).Standalone() + + 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 ") + 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(queryCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "file": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + "logfile": carapace.ActionFiles(), + "owns": carapace.ActionFiles(), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(queryCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if queryCmd.Flag("file").Changed { + return carapace.ActionFiles() + } + return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/remove.go b/completers/yay_completer/cmd/remove.go new file mode 100644 index 0000000000..a41d3fc38b --- /dev/null +++ b/completers/yay_completer/cmd/remove.go @@ -0,0 +1,64 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var removeCmd = &cobra.Command{ + Use: "remove", + Aliases: []string{"R"}, + Short: "Remove packages from the system", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(removeCmd).Standalone() + + removeCmd.Flags().String("arch", "", "set an alternate architecture") + removeCmd.Flags().String("assume-installed", "", "add a virtual package to satisfy dependencies") + removeCmd.Flags().String("cachedir", "", "set an alternate package cache location") + removeCmd.Flags().BoolP("cascade", "c", false, "remove packages and all packages that depend on them") + removeCmd.Flags().String("color", "", "colorize the output") + removeCmd.Flags().String("config", "", "set an alternate configuration file") + removeCmd.Flags().Bool("confirm", false, "always ask for confirmation") + removeCmd.Flags().Bool("dbonly", false, "only modify database entries, not package files") + removeCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location") + removeCmd.Flags().Bool("debug", false, "display debug messages") + removeCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download") + removeCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG") + removeCmd.Flags().String("hookdir", "", "set an alternate hook location") + removeCmd.Flags().String("logfile", "", "set an alternate log file") + removeCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation") + removeCmd.Flags().CountP("nodeps", "d", "skip dependency version checks (-dd to skip all checks)") + removeCmd.Flags().Bool("noprogressbar", false, "do not show a progress bar when downloading files") + removeCmd.Flags().BoolP("nosave", "n", false, "remove configuration files") + removeCmd.Flags().Bool("noscriptlet", false, "do not execute the install scriptlet if one exists") + removeCmd.Flags().BoolP("print", "p", false, "print the targets instead of performing the operation") + removeCmd.Flags().String("print-format", "", "specify how the targets should be printed") + removeCmd.Flags().CountP("recursive", "s", "remove unnecessary dependencies") + removeCmd.Flags().StringP("root", "r", "", "set an alternate installation root") + removeCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)") + removeCmd.Flags().BoolP("unneeded", "u", false, "remove unneeded packages") + removeCmd.Flags().BoolP("verbose", "v", false, "be verbose") + + carapace.Gen(removeCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + "logfile": carapace.ActionFiles(), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(removeCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackages().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/root.go b/completers/yay_completer/cmd/root.go new file mode 100644 index 0000000000..e6cb235da0 --- /dev/null +++ b/completers/yay_completer/cmd/root.go @@ -0,0 +1,44 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace-bin/pkg/util/embed" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "yay", + Short: "An AUR Helper written in Go", + Long: "https://github.com/Jguer/yay", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} + +func init() { + carapace.Gen(rootCmd).Standalone() + rootCmd.Flags().BoolP("version", "V", false, "show version") + + carapace.Gen(rootCmd).PositionalAnyCompletion( + pacman.ActionPackageSearch(), + ) + + // TODO add missing flags (permanent configuration, "new" flags, ...) + embed.SubcommandsAsFlags(rootCmd, + buildCmd, + databaseCmd, + deptestCmd, + filesCmd, + getpkgbuildCmd, + queryCmd, + removeCmd, + showCmd, + syncCmd, + upgradeCmd, + webCmd, + yayCmd, + ) +} diff --git a/completers/yay_completer/cmd/show.go b/completers/yay_completer/cmd/show.go new file mode 100644 index 0000000000..d28d60ac34 --- /dev/null +++ b/completers/yay_completer/cmd/show.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var showCmd = &cobra.Command{ + Use: "show", + Aliases: []string{"P"}, + Short: "", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(showCmd).Standalone() + + showCmd.Flags().BoolP("-c", "--complete", false, "Used for completions") + showCmd.Flags().BoolP("-d", "--defaultconfig", false, "Print default yay configuration") + showCmd.Flags().BoolP("-g", "--currentconfig", false, "Print current yay configuration") + showCmd.Flags().BoolP("-s", "--stats", false, "Display system package statistics") + showCmd.Flags().BoolP("-w", "--news", false, "Print arch news") +} diff --git a/completers/yay_completer/cmd/sync.go b/completers/yay_completer/cmd/sync.go new file mode 100644 index 0000000000..b4c8daba40 --- /dev/null +++ b/completers/yay_completer/cmd/sync.go @@ -0,0 +1,84 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var syncCmd = &cobra.Command{ + Use: "sync", + Aliases: []string{"S"}, + Short: "Synchronize packages", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(syncCmd).Standalone() + + syncCmd.Flags().String("arch", "", "set an alternate architecture") + syncCmd.Flags().Bool("asdeps", false, "install packages as non-explicitly installed") + syncCmd.Flags().Bool("asexplicit", false, "install packages as explicitly installed") + syncCmd.Flags().String("assume-installed", "", "add a virtual package to satisfy dependencies") + syncCmd.Flags().String("cachedir", "", "set an alternate package cache location") + syncCmd.Flags().CountP("clean", "c", "remove old packages from cache directory (-cc for all)") + syncCmd.Flags().String("color", "", "colorize the output") + syncCmd.Flags().String("config", "", "set an alternate configuration file") + syncCmd.Flags().Bool("confirm", false, "always ask for confirmation") + syncCmd.Flags().Bool("dbonly", false, "only modify database entries, not package files") + syncCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location") + syncCmd.Flags().Bool("debug", false, "display debug messages") + syncCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download") + syncCmd.Flags().BoolP("downloadonly", "w", false, "download packages but do not install/upgrade anything") + syncCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG") + syncCmd.Flags().CountP("groups", "g", "view all members of a package group") + syncCmd.Flags().String("hookdir", "", "set an alternate hook location") + syncCmd.Flags().StringSlice("ignore", []string{}, "ignore a package upgrade") + syncCmd.Flags().StringSlice("ignoregroup", []string{}, "ignore a group upgrade") + syncCmd.Flags().BoolP("info", "i", false, "view package information (-ii for extended information)") + syncCmd.Flags().StringP("list", "l", "", "view a list of packages in a repo") + syncCmd.Flags().String("logfile", "", "set an alternate log file") + syncCmd.Flags().Bool("needed", false, "do not reinstall up to date packages") + syncCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation") + syncCmd.Flags().BoolP("nodeps", "d", false, "skip dependency version checks (-dd to skip all checks)") + syncCmd.Flags().Bool("noprogressbar", false, "do not show a progress bar when downloading files") + syncCmd.Flags().Bool("noscriptlet", false, "do not execute the install scriptlet if one exists") + syncCmd.Flags().StringSlice("overwrite", []string{}, "overwrite conflicting files") + syncCmd.Flags().BoolP("print", "p", false, "print the targets instead of performing the operation") + syncCmd.Flags().String("print-format", "", "specify how the targets should be printed") + syncCmd.Flags().BoolP("quiet", "q", false, "show less information for query and search") + syncCmd.Flags().CountP("refresh", "y", "download fresh package databases from the server") + syncCmd.Flags().StringP("root", "r", "", "set an alternate installation root") + syncCmd.Flags().StringP("search", "s", "", "search remote repositories for matching strings") + syncCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)") + syncCmd.Flags().CountP("sysupgrade", "u", "upgrade installed packages (-uu enables downgrades)") + syncCmd.Flags().BoolP("verbose", "v", false, "be verbose") + + carapace.Gen(syncCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + // TODO list + "ignore": pacman.ActionPackageSearch().UniqueList(","), + "ignoregroup": pacman.ActionPackageGroups().UniqueList(","), + "logfile": carapace.ActionFiles(), + "overwrite": carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if len(c.Args) > 0 { + return pacman.ActionPackageFiles(c.Args...).List(",") + } + return carapace.ActionValues() + }), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(syncCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/upgrade.go b/completers/yay_completer/cmd/upgrade.go new file mode 100644 index 0000000000..a25a381bf0 --- /dev/null +++ b/completers/yay_completer/cmd/upgrade.go @@ -0,0 +1,72 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +var upgradeCmd = &cobra.Command{ + Use: "upgrade", + Aliases: []string{"U"}, + Short: "Upgrade or add packages", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(upgradeCmd).Standalone() + + upgradeCmd.Flags().String("arch", "", "set an alternate architecture") + upgradeCmd.Flags().Bool("asdeps", false, "install packages as non-explicitly installed") + upgradeCmd.Flags().Bool("asexplicit", false, "install packages as explicitly installed") + upgradeCmd.Flags().String("assume-installed", "", "add a virtual package to satisfy dependencies") + upgradeCmd.Flags().String("cachedir", "", "set an alternate package cache location") + upgradeCmd.Flags().String("color", "", "colorize the output") + upgradeCmd.Flags().String("config", "", "set an alternate configuration file") + upgradeCmd.Flags().Bool("confirm", false, "always ask for confirmation") + upgradeCmd.Flags().Bool("dbonly", false, "only modify database entries, not package files") + upgradeCmd.Flags().StringP("dbpath", "b", "", "set an alternate database location") + upgradeCmd.Flags().Bool("debug", false, "display debug messages") + upgradeCmd.Flags().Bool("disable-download-timeout", false, "use relaxed timeouts for download") + upgradeCmd.Flags().BoolP("downloadonly", "w", false, "download packages but do not install/upgrade anything") + upgradeCmd.Flags().String("gpgdir", "", "set an alternate home directory for GnuPG") + upgradeCmd.Flags().String("hookdir", "", "set an alternate hook location") + upgradeCmd.Flags().StringSlice("ignore", []string{}, "ignore a package upgrade") + upgradeCmd.Flags().StringSlice("ignoregroup", []string{}, "ignore a group upgrade") + upgradeCmd.Flags().String("logfile", "", "set an alternate log file") + upgradeCmd.Flags().Bool("needed", false, "do not reinstall up to date packages") + upgradeCmd.Flags().Bool("noconfirm", false, "do not ask for any confirmation") + upgradeCmd.Flags().CountP("nodeps", "d", "skip dependency version checks (-dd to skip all checks)") + upgradeCmd.Flags().Bool("noprogressbar", false, "do not show a progress bar when downloading files") + upgradeCmd.Flags().Bool("noscriptlet", false, "do not execute the install scriptlet if one exists") + upgradeCmd.Flags().StringSlice("overwrite", []string{}, "overwrite conflicting files") + upgradeCmd.Flags().BoolP("print", "p", false, "print the targets instead of performing the operation") + upgradeCmd.Flags().String("print-format", "", "specify how the targets should be printed") + upgradeCmd.Flags().StringP("root", "r", "", "set an alternate installation root") + upgradeCmd.Flags().Bool("sysroot", false, "operate on a mounted guest system (root-only)") + upgradeCmd.Flags().BoolP("verbose", "v", false, "be verbose") + + carapace.Gen(upgradeCmd).FlagCompletion(carapace.ActionMap{ + "arch": carapace.ActionValues("i686", "x86_64"), + "cachedir": carapace.ActionDirectories(), + "color": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword), + "config": carapace.ActionFiles(), + "dbpath": carapace.ActionFiles(), + "gpgdir": carapace.ActionDirectories(), + "hookdir": carapace.ActionDirectories(), + "ignore": pacman.ActionPackageSearch().UniqueList(","), + "ignoregroup": pacman.ActionPackageGroups().UniqueList(","), + "logfile": carapace.ActionFiles(), + "overwrite": carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if len(c.Args) > 0 { + return pacman.ActionPackageFiles(c.Args...).List(",") + } + return carapace.ActionValues() + }), + "root": carapace.ActionDirectories(), + }) + + carapace.Gen(upgradeCmd).PositionalAnyCompletion(carapace.ActionFiles()) + +} diff --git a/completers/yay_completer/cmd/web.go b/completers/yay_completer/cmd/web.go new file mode 100644 index 0000000000..94b346e4bb --- /dev/null +++ b/completers/yay_completer/cmd/web.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/spf13/cobra" +) + +var webCmd = &cobra.Command{ + Use: "web", + Aliases: []string{"W"}, + Short: "", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(webCmd).Standalone() + + carapace.Gen(webCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/cmd/yay.go b/completers/yay_completer/cmd/yay.go new file mode 100644 index 0000000000..6bec5289fc --- /dev/null +++ b/completers/yay_completer/cmd/yay.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/spf13/cobra" +) + +var yayCmd = &cobra.Command{ + Use: "yay", + Aliases: []string{"Y"}, + Short: "", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(yayCmd).Standalone() + + yayCmd.Flags().BoolP("clean", "c", false, "Remove unneeded dependencies") + yayCmd.Flags().Bool("gendb", false, "Generates development package DB used for updating") + + carapace.Gen(yayCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return pacman.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/yay_completer/main.go b/completers/yay_completer/main.go new file mode 100644 index 0000000000..a39b821d51 --- /dev/null +++ b/completers/yay_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/rsteube/carapace-bin/completers/yay_completer/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/util/embed/flag.go b/pkg/util/embed/flag.go new file mode 100644 index 0000000000..9d1d750efc --- /dev/null +++ b/pkg/util/embed/flag.go @@ -0,0 +1,51 @@ +package embed + +import ( + "strings" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" +) + +// SubcommandsAsFlags embeds subcommands as flags (e.g. `pacman -Syu` where `S` is actually a subcommand). +// Supports a single alias that is used as shorthand. +func SubcommandsAsFlags(cmd *cobra.Command, subcommands ...*cobra.Command) { + carapace.Gen(cmd).PreRun(func(cmd *cobra.Command, args []string) { + flags := pflag.NewFlagSet("subcommands", pflag.ContinueOnError) + for _, s := range subcommands { + if len(s.Aliases) > 0 { + flags.BoolP(s.Name(), s.Aliases[0], false, s.Short) // suppport one alias as shorthand + } else { + flags.Bool(s.Name(), false, s.Short) + } + } + + switch { + case strings.HasPrefix(args[0], "--"): + flags.Parse(args[:1]) + case strings.HasPrefix(args[0], "-") && len(args[0]) > 1: + flags.Parse([]string{args[0][:2]}) + } + + var subcommand *cobra.Command + flags.Visit(func(f *pflag.Flag) { + for _, s := range subcommands { + if f.Name == s.Name() { + subcommand = s + subcommand.Flags().AddFlag(f) + } + } + }) + + switch { + case subcommand != nil: + cmd.DisableFlagParsing = true + carapace.Gen(cmd).PositionalAnyCompletion( + carapace.ActionExecute(subcommand), + ) + case len(args) < 2: + cmd.Flags().AddFlagSet(flags) + } + }) +}