Skip to content

Commit

Permalink
Merge pull request #144 from rsteube/bridge-macro
Browse files Browse the repository at this point in the history
bridge spec macro
  • Loading branch information
rsteube committed Feb 3, 2024
2 parents a62f82c + e6bf852 commit a301d7a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/carapace-bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ 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("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
16 changes: 16 additions & 0 deletions pkg/actions/bridge/carapace.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,19 @@ func actionCommand(command ...string) func(f func(command ...string) carapace.Ac
})
}
}

// ActionCarapace bridges macros exposed with https://github.com/rsteube/carapace-bin
func ActionMacro(command ...string) carapace.Action {
return actionCommand(command...)(func(command ...string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := []string{"_carapace", "macro"}
args = append(args, command[1:]...)
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)
})
})
})
}

0 comments on commit a301d7a

Please sign in to comment.