diff --git a/cmd/carapace-bridge/cmd/root.go b/cmd/carapace-bridge/cmd/root.go index b3e6e81..f3189be 100644 --- a/cmd/carapace-bridge/cmd/root.go +++ b/cmd/carapace-bridge/cmd/root.go @@ -49,19 +49,7 @@ func init() { addSubCommand("fish", "bridges completions registered in fish", bridge.ActionFish) addSubCommand("inshellisense", "bridges https://github.com/microsoft/inshellisense", bridge.ActionInshellisense) addSubCommand("kingpin", "bridges https://github.com/alecthomas/kingpin", bridge.ActionKingpin) - addSubCommand("macro", "bridges macros exposed with https://github.com/rsteube/carapace-spec", func(s ...string) carapace.Action { - return carapace.ActionCallback(func(c carapace.Context) carapace.Action { - switch len(c.Args) { - case 0: - return carapace.ActionExecCommand(s[0], "_carapace", "macro")(func(output []byte) carapace.Action { - lines := strings.Split(string(output), "\n") - return carapace.ActionValues(lines[:len(lines)-1]...).MultiParts(".") - }) - default: - return bridge.ActionMacro(s[0], c.Args[0]).Shift(1) - } - }) - }) + addSubCommand("macro", "bridges macros exposed with https://github.com/rsteube/carapace-spec", bridge.ActionMacro) addSubCommand("powershell", "bridges completions registered in powershell", bridge.ActionPowershell) addSubCommand("urfavecli", "bridges https://github.com/urfave/cli", bridge.ActionUrfavecli) addSubCommand("yargs", "bridges https://github.com/yargs/yargs", bridge.ActionYargs) diff --git a/pkg/actions/bridge/carapace.go b/pkg/actions/bridge/carapace.go index fc73b83..1c8bf1a 100644 --- a/pkg/actions/bridge/carapace.go +++ b/pkg/actions/bridge/carapace.go @@ -3,6 +3,7 @@ package bridge import ( "os" "path/filepath" + "strings" "github.com/rsteube/carapace" "github.com/spf13/cobra" @@ -86,9 +87,17 @@ func ActionMacro(command ...string) carapace.Action { args = append(args, c.Args...) args = append(args, c.Value) - return carapace.ActionExecCommand(command[0], args...)(func(output []byte) carapace.Action { - return carapace.ActionImport(output) - }) + switch len(append(command, c.Args...)) { + case 1: + return carapace.ActionExecCommand(command[0], "_carapace", "macro")(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + return carapace.ActionValues(lines[:len(lines)-1]...).MultiParts(".") + }) + default: + return carapace.ActionExecCommand(command[0], args...)(func(output []byte) carapace.Action { + return carapace.ActionImport(output) + }).Shift(1) + } }) }) }