Skip to content

Commit

Permalink
ActionMacro: fix args
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 3, 2024
1 parent a301d7a commit 1dd7dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 1 addition & 13 deletions cmd/carapace-bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions pkg/actions/bridge/carapace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bridge
import (
"os"
"path/filepath"
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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)
}
})
})
}

0 comments on commit 1dd7dfc

Please sign in to comment.