From 1ef32ee2cfd9a9df78c675d2e381397e6cc2514c Mon Sep 17 00:00:00 2001 From: rsteube Date: Fri, 22 Dec 2023 22:49:19 +0100 Subject: [PATCH] carapace: renamed macro flag/subcommand --- cmd/carapace/cmd/codegen.go | 2 +- cmd/carapace/cmd/{macros.go => macro.go} | 14 ++++++------ cmd/carapace/cmd/macros_test.go | 4 ++-- cmd/carapace/cmd/root.go | 28 ++++++++++++------------ docs/src/release_notes/v0.29.md | 3 ++- docs/src/spec.md | 6 ++--- 6 files changed, 29 insertions(+), 28 deletions(-) rename cmd/carapace/cmd/{macros.go => macro.go} (86%) diff --git a/cmd/carapace/cmd/codegen.go b/cmd/carapace/cmd/codegen.go index dd7e5f5491..247c0355ad 100644 --- a/cmd/carapace/cmd/codegen.go +++ b/cmd/carapace/cmd/codegen.go @@ -6,7 +6,7 @@ import ( ) var codegenCmd = &cobra.Command{ - Use: "--scrape [spec]", + Use: "--codegen [spec]", Short: "", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/carapace/cmd/macros.go b/cmd/carapace/cmd/macro.go similarity index 86% rename from cmd/carapace/cmd/macros.go rename to cmd/carapace/cmd/macro.go index 13349eb787..a0bb0f80e4 100644 --- a/cmd/carapace/cmd/macros.go +++ b/cmd/carapace/cmd/macro.go @@ -13,8 +13,8 @@ import ( "github.com/spf13/cobra" ) -var macrosCmd = &cobra.Command{ - Use: "--macros [macro] ...", +var macroCmd = &cobra.Command{ + Use: "--macro [macro] ...", Short: "", Args: cobra.ArbitraryArgs, Run: func(cmd *cobra.Command, args []string) { @@ -30,14 +30,14 @@ var macrosCmd = &cobra.Command{ } func init() { - carapace.Gen(macrosCmd).Standalone() - macrosCmd.Flags().SetInterspersed(false) + carapace.Gen(macroCmd).Standalone() + macroCmd.Flags().SetInterspersed(false) - carapace.Gen(macrosCmd).PositionalCompletion( + carapace.Gen(macroCmd).PositionalCompletion( carapace.ActionMultiPartsN("(", 2, func(c carapace.Context) carapace.Action { switch len(c.Parts) { case 0: - return carapace.ActionExecCommand("carapace", "--macros")(func(output []byte) carapace.Action { + return carapace.ActionExecCommand("carapace", "--macro")(func(output []byte) carapace.Action { lines := strings.Split(string(output), "\n") vals := make([]string, 0) @@ -59,7 +59,7 @@ func init() { }), ) - carapace.Gen(macrosCmd).PositionalAnyCompletion( + carapace.Gen(macroCmd).PositionalAnyCompletion( carapace.ActionCallback(func(c carapace.Context) carapace.Action { return spec.ActionMacro("$carapace." + c.Args[0]).Shift(1) // TODO macro prefix }), diff --git a/cmd/carapace/cmd/macros_test.go b/cmd/carapace/cmd/macros_test.go index 36b31a5940..ff9fdaf4a8 100644 --- a/cmd/carapace/cmd/macros_test.go +++ b/cmd/carapace/cmd/macros_test.go @@ -9,10 +9,10 @@ import ( func TestMacros(t *testing.T) { sandbox.Package(t, "github.com/rsteube/carapace-bin/cmd/carapace")(func(s *sandbox.Sandbox) { - s.Run("--macros", "color.XtermColorNames", "G"). + s.Run("--macro", "color.XtermColorNames", "G"). Expect(carapace.ActionStyledValues( "Green", "color2", "Grey", "color8", - ).Usage("--macros [macro] ...")) + ).Usage("--macro [macro] ...")) }) } diff --git a/cmd/carapace/cmd/root.go b/cmd/carapace/cmd/root.go index f375d143f7..0960ac75f0 100644 --- a/cmd/carapace/cmd/root.go +++ b/cmd/carapace/cmd/root.go @@ -59,9 +59,9 @@ var rootCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // since flag parsing is disabled do this manually switch args[0] { - case "--macros": - macrosCmd.SetArgs(args[1:]) - macrosCmd.Execute() + case "--macro": + macroCmd.SetArgs(args[1:]) + macroCmd.Execute() case "-h", "--help": cmd.Help() case "-v", "--version": @@ -238,20 +238,20 @@ func Execute(version string) error { } func init() { - rootCmd.Flags().Bool("codegen", false, "generate code from spec file") - rootCmd.Flags().Bool("list", false, "list completers") - rootCmd.Flags().Bool("macros", false, "list spec macros") + rootCmd.Flags().Bool("codegen", false, "generate code for spec file") rootCmd.Flags().BoolP("help", "h", false, "help for carapace") - rootCmd.Flags().BoolP("version", "v", false, "version for carapace") + rootCmd.Flags().Bool("list", false, "list completers") + rootCmd.Flags().Bool("macro", false, "list or execute macros") rootCmd.Flags().Bool("run", false, "run spec") rootCmd.Flags().Bool("schema", false, "json schema for spec files") rootCmd.Flags().Bool("style", false, "set style") + rootCmd.Flags().BoolP("version", "v", false, "version for carapace") rootCmd.MarkFlagsMutuallyExclusive( "codegen", "help", "list", - "macros", + "macro", "run", "schema", "style", @@ -275,22 +275,22 @@ func init() { return carapace.ActionExecute(invokeCmd) } switch c.Args[0] { - case "--macros": - return carapace.ActionExecute(macrosCmd).Shift(1) + case "--codegen": + return carapace.ActionExecute(codegenCmd).Shift(1) case "--help": return carapace.ActionValues() - case "-v", "--version": - return carapace.ActionValues() case "--list": return carapace.ActionExecute(listCmd).Shift(1).Usage("list") + case "--macro": + return carapace.ActionExecute(macroCmd).Shift(1) case "--run": return carapace.ActionExecute(runCmd).Shift(1) case "--schema": return carapace.ActionExecute(schemaCmd).Shift(1) - case "--scrape": - return carapace.ActionExecute(codegenCmd).Shift(1) case "--style": return carapace.ActionExecute(styleCmd).Shift(1) + case "-v", "--version": + return carapace.ActionValues() default: return carapace.ActionValues() } diff --git a/docs/src/release_notes/v0.29.md b/docs/src/release_notes/v0.29.md index cc80000a5e..39440b801d 100644 --- a/docs/src/release_notes/v0.29.md +++ b/docs/src/release_notes/v0.29.md @@ -2,7 +2,7 @@ ![](./v0.29/banner.png) -One step further to exchange completions _loosely coupled_ between commands. +One step further to exchange completions between commands. ## Root Command @@ -10,6 +10,7 @@ Restructured the `carapace` root command which was (and still is) a bit of a mes Some "flags" (subcommands) were renamed/changed for consistency. - `--list=json` -> `--list --format json` +- `--macros` -> `--macro` - `--scrape [spec]` -> `--codegen [spec]` ## Macro diff --git a/docs/src/spec.md b/docs/src/spec.md index a3a8cf6127..a36ca488d8 100644 --- a/docs/src/spec.md +++ b/docs/src/spec.md @@ -33,9 +33,9 @@ commands: Carapace provides a range of [custom macros](./spec/macros.md): ```sh -carapace --macros # list macros -carapace --macros color.HexColors # show macro details -carapace --macros color.HexColors # test macro +carapace --macro # list macros +carapace --macro color.HexColors # show macro details +carapace --macro color.HexColors # test macro ``` ![](./spec-macros.cast)