Skip to content

Commit af92c8e

Browse files
authored
Merge pull request #3093 from carapace-sh/but-rub-root
but: added rub completion for root
2 parents 4d36ec5 + 81050ea commit af92c8e

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

completers/common/but_completer/cmd/forge.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
)
77

88
var forgeCmd = &cobra.Command{
9-
Use: "forge",
10-
Short: "Commands for interacting with forges like GitHub, GitLab (coming soon), etc",
11-
Run: func(cmd *cobra.Command, args []string) {},
9+
Use: "forge",
10+
Short: "Commands for interacting with forges like GitHub, GitLab (coming soon), etc",
11+
Run: func(cmd *cobra.Command, args []string) {},
12+
GroupID: "server interactions",
1213
}
1314

1415
func init() {

completers/common/but_completer/cmd/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var pushCmd = &cobra.Command{
1010
Use: "push BRANCH_ID",
1111
Short: "Push changes in a branch to remote",
1212
Run: func(cmd *cobra.Command, args []string) {},
13-
GroupID: "branching and committing",
13+
GroupID: "server interactions",
1414
}
1515

1616
func init() {

completers/common/but_completer/cmd/review.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
)
77

88
var reviewCmd = &cobra.Command{
9-
Use: "review",
10-
Short: "Commands for creating and publishing code reviews to a forge",
11-
Run: func(cmd *cobra.Command, args []string) {},
9+
Use: "review",
10+
Short: "Commands for creating and publishing code reviews to a forge",
11+
Run: func(cmd *cobra.Command, args []string) {},
12+
GroupID: "server interactions",
1213
}
1314

1415
func init() {

completers/common/but_completer/cmd/root.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package cmd
22

33
import (
44
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/but"
56
"github.com/carapace-sh/carapace/pkg/traverse"
7+
"github.com/carapace-sh/carapace/pkg/util"
68
"github.com/spf13/cobra"
79
"github.com/spf13/pflag"
810
)
@@ -22,9 +24,10 @@ func init() {
2224
carapace.Gen(rootCmd).Standalone()
2325

2426
rootCmd.AddGroup(
27+
&cobra.Group{ID: "inspection"},
2528
&cobra.Group{ID: "branching and committing"},
29+
&cobra.Group{ID: "server interactions"},
2630
&cobra.Group{ID: "editing commits"},
27-
&cobra.Group{ID: "inspection"},
2831
&cobra.Group{ID: "operation history"},
2932
)
3033

@@ -40,7 +43,16 @@ func init() {
4043
})
4144

4245
carapace.Gen(rootCmd).PositionalCompletion(
43-
carapace.ActionDirectories(),
46+
carapace.Batch(
47+
but.ActionCliIds(but.CliIdsOpts{}.Default()),
48+
carapace.ActionDirectories(),
49+
).ToA(),
50+
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
51+
if util.HasPathPrefix(c.Args[0]) {
52+
return carapace.ActionValues()
53+
}
54+
return but.ActionCliIds(but.CliIdsOpts{Branches: true, Stacks: true})
55+
}),
4456
)
4557

4658
carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, _ *pflag.Flag, action carapace.Action) carapace.Action {

0 commit comments

Comments
 (0)