From 65608982cd1dc6106c23ea9d8c5147f80d289b29 Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 15 Dec 2022 23:10:13 +0100 Subject: [PATCH] cargo: added command groups --- completers/cargo_completer/cmd/add.go | 7 ++- completers/cargo_completer/cmd/bench.go | 7 ++- completers/cargo_completer/cmd/build.go | 1 + completers/cargo_completer/cmd/check.go | 1 + completers/cargo_completer/cmd/clean.go | 7 ++- completers/cargo_completer/cmd/doc.go | 7 ++- completers/cargo_completer/cmd/fetch.go | 7 ++- completers/cargo_completer/cmd/fix.go | 7 ++- completers/cargo_completer/cmd/init.go | 7 ++- completers/cargo_completer/cmd/install.go | 7 ++- completers/cargo_completer/cmd/new.go | 7 ++- completers/cargo_completer/cmd/publish.go | 7 ++- completers/cargo_completer/cmd/root.go | 69 ++++++++++++++++++++- completers/cargo_completer/cmd/run.go | 1 + completers/cargo_completer/cmd/search.go | 7 ++- completers/cargo_completer/cmd/test.go | 1 + completers/cargo_completer/cmd/uninstall.go | 7 ++- completers/cargo_completer/cmd/update.go | 7 ++- 18 files changed, 123 insertions(+), 41 deletions(-) diff --git a/completers/cargo_completer/cmd/add.go b/completers/cargo_completer/cmd/add.go index 486879f017..fff7357f52 100644 --- a/completers/cargo_completer/cmd/add.go +++ b/completers/cargo_completer/cmd/add.go @@ -11,9 +11,10 @@ import ( ) var addCmd = &cobra.Command{ - Use: "add", - Short: "Add dependency to a Cargo.toml manifest file", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "add", + Short: "Add dependency to a Cargo.toml manifest file", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("add"), } func init() { diff --git a/completers/cargo_completer/cmd/bench.go b/completers/cargo_completer/cmd/bench.go index 791892d243..538e5a33e9 100644 --- a/completers/cargo_completer/cmd/bench.go +++ b/completers/cargo_completer/cmd/bench.go @@ -8,9 +8,10 @@ import ( ) var benchCmd = &cobra.Command{ - Use: "bench", - Short: "Execute all benchmarks of a local package", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "bench", + Short: "Execute all benchmarks of a local package", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("bench"), } func init() { diff --git a/completers/cargo_completer/cmd/build.go b/completers/cargo_completer/cmd/build.go index 0217f3decd..d7aff381ef 100644 --- a/completers/cargo_completer/cmd/build.go +++ b/completers/cargo_completer/cmd/build.go @@ -12,6 +12,7 @@ var buildCmd = &cobra.Command{ Aliases: []string{"b"}, Short: "Compile a local package and all of its dependencies", Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("build"), } func init() { diff --git a/completers/cargo_completer/cmd/check.go b/completers/cargo_completer/cmd/check.go index 7e427dcdd5..eb9ee251e9 100644 --- a/completers/cargo_completer/cmd/check.go +++ b/completers/cargo_completer/cmd/check.go @@ -12,6 +12,7 @@ var checkCmd = &cobra.Command{ Aliases: []string{"c"}, Short: "Check a local package and all of its dependencies for errors", Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("check"), } func init() { diff --git a/completers/cargo_completer/cmd/clean.go b/completers/cargo_completer/cmd/clean.go index 0f4695dba6..e8aac92053 100644 --- a/completers/cargo_completer/cmd/clean.go +++ b/completers/cargo_completer/cmd/clean.go @@ -7,9 +7,10 @@ import ( ) var cleanCmd = &cobra.Command{ - Use: "clean", - Short: "Remove artifacts that cargo has generated in the past", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "clean", + Short: "Remove artifacts that cargo has generated in the past", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("clean"), } func init() { diff --git a/completers/cargo_completer/cmd/doc.go b/completers/cargo_completer/cmd/doc.go index 55f17bd4f1..dfa63da224 100644 --- a/completers/cargo_completer/cmd/doc.go +++ b/completers/cargo_completer/cmd/doc.go @@ -8,9 +8,10 @@ import ( ) var docCmd = &cobra.Command{ - Use: "doc", - Short: "Build a package's documentation", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "doc", + Short: "Build a package's documentation", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("doc"), } func init() { diff --git a/completers/cargo_completer/cmd/fetch.go b/completers/cargo_completer/cmd/fetch.go index 0bac017d5d..2751cf87f4 100644 --- a/completers/cargo_completer/cmd/fetch.go +++ b/completers/cargo_completer/cmd/fetch.go @@ -7,9 +7,10 @@ import ( ) var fetchCmd = &cobra.Command{ - Use: "fetch", - Short: "", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "fetch", + Short: "", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("fetch"), } func init() { diff --git a/completers/cargo_completer/cmd/fix.go b/completers/cargo_completer/cmd/fix.go index 36eb137e1a..e80b7b5a28 100644 --- a/completers/cargo_completer/cmd/fix.go +++ b/completers/cargo_completer/cmd/fix.go @@ -8,9 +8,10 @@ import ( ) var fixCmd = &cobra.Command{ - Use: "fix", - Short: "Automatically fix lint warnings reported by rustc", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "fix", + Short: "Automatically fix lint warnings reported by rustc", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("fix"), } func init() { diff --git a/completers/cargo_completer/cmd/init.go b/completers/cargo_completer/cmd/init.go index 87b10985be..7b085fb026 100644 --- a/completers/cargo_completer/cmd/init.go +++ b/completers/cargo_completer/cmd/init.go @@ -7,9 +7,10 @@ import ( ) var initCmd = &cobra.Command{ - Use: "init", - Short: "Create a new cargo package in an existing directory", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "init", + Short: "Create a new cargo package in an existing directory", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("init"), } func init() { diff --git a/completers/cargo_completer/cmd/install.go b/completers/cargo_completer/cmd/install.go index 7c1e4dbb61..e49b25cd9a 100644 --- a/completers/cargo_completer/cmd/install.go +++ b/completers/cargo_completer/cmd/install.go @@ -8,9 +8,10 @@ import ( ) var installCmd = &cobra.Command{ - Use: "install", - Short: "Install a Rust binary", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "install", + Short: "Install a Rust binary", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("install"), } func init() { diff --git a/completers/cargo_completer/cmd/new.go b/completers/cargo_completer/cmd/new.go index bd692848ca..e15a149349 100644 --- a/completers/cargo_completer/cmd/new.go +++ b/completers/cargo_completer/cmd/new.go @@ -7,9 +7,10 @@ import ( ) var newCmd = &cobra.Command{ - Use: "new", - Short: "Create a new cargo package at ", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "new", + Short: "Create a new cargo package at ", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("new"), } func init() { diff --git a/completers/cargo_completer/cmd/publish.go b/completers/cargo_completer/cmd/publish.go index ae12f99585..33669f29c2 100644 --- a/completers/cargo_completer/cmd/publish.go +++ b/completers/cargo_completer/cmd/publish.go @@ -8,9 +8,10 @@ import ( ) var publishCmd = &cobra.Command{ - Use: "publish", - Short: "Upload a package to the registry", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "publish", + Short: "Upload a package to the registry", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("publish"), } func init() { diff --git a/completers/cargo_completer/cmd/root.go b/completers/cargo_completer/cmd/root.go index 10b2d83a1d..3daef52549 100644 --- a/completers/cargo_completer/cmd/root.go +++ b/completers/cargo_completer/cmd/root.go @@ -19,10 +19,29 @@ var rootCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) {}, } +const ( + group_build = iota + group_manifest + group_package + group_publishing + group_general +) + +var groups = []*cobra.Group{ + {ID: "build", Title: "Build Commands"}, + {ID: "manifest", Title: "Manifest Commands"}, + {ID: "package", Title: "Package Commands"}, + {ID: "publishing", Title: "Publishing Commands"}, + {ID: "general", Title: "General Commands"}, +} + func Execute() error { return rootCmd.Execute() } + func init() { + rootCmd.AddGroup(groups...) + carapace.Gen(rootCmd).Standalone() rootCmd.Flags().StringS("Z", "Z", "", "Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") @@ -51,8 +70,9 @@ func init() { if matches := re.FindStringSubmatch(line); matches != nil { pluginCmd := &cobra.Command{ Use: matches[1], - Short: matches[2], + Short: matches[3], Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor(matches[1]), DisableFlagParsing: true, } @@ -63,7 +83,52 @@ func init() { rootCmd.AddCommand(pluginCmd) } } - } }) } + +func groupFor(name string) string { + // https: //doc.rust-lang.org/cargo/commands/index.html + switch name { + case "help", + "version": + return groups[group_general].ID + case "bench", + "build", + "check", + "clean", + "doc", + "fetch", + "fix", + "run", + "rustc", + "rustdoc", + "test", + "report": + return groups[group_build].ID + case "add", + "generate-lockfile", + "locate-project", + "metadata", + "pkgid", + "remove", + "tree", + "update", + "vendor", + "verify-project": + return groups[group_manifest].ID + case "init", + "new", + "search", + "uninstall": + return groups[group_package].ID + case "login", + "owner", + "package", + "publish", + "yank": + return groups[group_publishing].ID + default: + return "" + } +} diff --git a/completers/cargo_completer/cmd/run.go b/completers/cargo_completer/cmd/run.go index 191fcc9c41..02468c5202 100644 --- a/completers/cargo_completer/cmd/run.go +++ b/completers/cargo_completer/cmd/run.go @@ -12,6 +12,7 @@ var runCmd = &cobra.Command{ Aliases: []string{"r"}, Short: "Run a binary or example of the local package", Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("run"), } func init() { diff --git a/completers/cargo_completer/cmd/search.go b/completers/cargo_completer/cmd/search.go index 0a992299b2..097ccb3ef3 100644 --- a/completers/cargo_completer/cmd/search.go +++ b/completers/cargo_completer/cmd/search.go @@ -7,9 +7,10 @@ import ( ) var searchCmd = &cobra.Command{ - Use: "search", - Short: "Search packages in crates.io", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "search", + Short: "Search packages in crates.io", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("search"), } func init() { diff --git a/completers/cargo_completer/cmd/test.go b/completers/cargo_completer/cmd/test.go index 0b14042eb9..a6b5d6ff49 100644 --- a/completers/cargo_completer/cmd/test.go +++ b/completers/cargo_completer/cmd/test.go @@ -12,6 +12,7 @@ var testCmd = &cobra.Command{ Aliases: []string{"t"}, Short: "Execute all unit and integration tests and build examples of a local package", Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("test"), } func init() { diff --git a/completers/cargo_completer/cmd/uninstall.go b/completers/cargo_completer/cmd/uninstall.go index c4b5ca15f4..11074e6df1 100644 --- a/completers/cargo_completer/cmd/uninstall.go +++ b/completers/cargo_completer/cmd/uninstall.go @@ -7,9 +7,10 @@ import ( ) var uninstallCmd = &cobra.Command{ - Use: "uninstall", - Short: "Remove a Rust binary", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "uninstall", + Short: "Remove a Rust binary", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("uninstall"), } func init() { diff --git a/completers/cargo_completer/cmd/update.go b/completers/cargo_completer/cmd/update.go index 683b65ad00..1f487aad27 100644 --- a/completers/cargo_completer/cmd/update.go +++ b/completers/cargo_completer/cmd/update.go @@ -7,9 +7,10 @@ import ( ) var updateCmd = &cobra.Command{ - Use: "update", - Short: "Update dependencies as recorded in the local lock file", - Run: func(cmd *cobra.Command, args []string) {}, + Use: "update", + Short: "Update dependencies as recorded in the local lock file", + Run: func(cmd *cobra.Command, args []string) {}, + GroupID: groupFor("update"), } func init() {