Skip to content

Commit

Permalink
carapace: renamed macro flag/subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 22, 2023
1 parent 85c2c05 commit 1708472
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions cmd/carapace/cmd/macros.go → cmd/carapace/cmd/macro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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
}),
Expand Down
2 changes: 1 addition & 1 deletion cmd/carapace/cmd/macros_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions cmd/carapace/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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")
Expand All @@ -251,7 +251,7 @@ func init() {
"codegen",
"help",
"list",
"macros",
"macro",
"run",
"schema",
"style",
Expand All @@ -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":
Expand Down

0 comments on commit 1708472

Please sign in to comment.