Skip to content

Commit

Permalink
Merge pull request #1271 from rsteube/rustup-default-channels
Browse files Browse the repository at this point in the history
rustup: default channel completion
  • Loading branch information
rsteube authored Aug 22, 2022
2 parents 476a1f4 + 0ef69c8 commit ebd4017
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions completers/rustup_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

func ActionDefaultChannels() carapace.Action {
return carapace.ActionStyledValues(
"stable", style.Green,
"beta", style.Yellow,
"nightly", style.Red,
)
}

func ActionToolchains() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("rustup", "toolchain", "list")(func(output []byte) carapace.Action {
Expand Down
5 changes: 4 additions & 1 deletion completers/rustup_completer/cmd/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func init() {
rootCmd.AddCommand(defaultCmd)

carapace.Gen(defaultCmd).PositionalCompletion(
action.ActionToolchains(),
carapace.Batch(
action.ActionDefaultChannels(),
action.ActionToolchains(),
).ToA(),
)
}
2 changes: 1 addition & 1 deletion completers/rustup_completer/cmd/toolchain_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {

carapace.Gen(toolchain_installCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionValues("beta", "nightly", "stable").Invoke(c).Filter(c.Args).ToA()
return action.ActionDefaultChannels().Invoke(c).Filter(c.Args).ToA()
}),
)
}

0 comments on commit ebd4017

Please sign in to comment.