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..b0f193a5f0 100644 --- a/cmd/carapace/cmd/macros_test.go +++ b/cmd/carapace/cmd/macros_test.go @@ -9,7 +9,7 @@ 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", diff --git a/cmd/carapace/cmd/root.go b/cmd/carapace/cmd/root.go index f375d143f7..2c1d232de4 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": @@ -240,7 +240,7 @@ 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("macro", false, "list or execute macros") rootCmd.Flags().BoolP("help", "h", false, "help for carapace") rootCmd.Flags().BoolP("version", "v", false, "version for carapace") rootCmd.Flags().Bool("run", false, "run spec") @@ -251,7 +251,7 @@ func init() { "codegen", "help", "list", - "macros", + "macro", "run", "schema", "style", @@ -275,8 +275,8 @@ func init() { return carapace.ActionExecute(invokeCmd) } switch c.Args[0] { - case "--macros": - return carapace.ActionExecute(macrosCmd).Shift(1) + case "--macro": + return carapace.ActionExecute(macroCmd).Shift(1) case "--help": return carapace.ActionValues() case "-v", "--version":