Skip to content

Commit 0679f69

Browse files
authored
fix: cli completions should filter by verb (#288)
1 parent 80775e2 commit 0679f69

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

cmd/internal/browse.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ func RegisterBrowseCmd(ctx *context.Context, rootCmd *cobra.Command) {
3333
),
3434
Args: cobra.MaximumNArgs(2),
3535
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
36+
verbStr := cmd.CalledAs()
37+
verb := executable.Verb(verbStr)
3638
execList, err := ctx.ExecutableCache.GetExecutableList()
3739
if err != nil {
3840
return nil, cobra.ShellCompDirectiveError
3941
}
4042
execIDs := make([]string, 0, len(execList))
4143
for _, e := range execList {
42-
execIDs = append(execIDs, e.ID())
44+
if e.Verb.Equals(verb) {
45+
execIDs = append(execIDs, e.ID())
46+
}
4347
}
4448
return execIDs, cobra.ShellCompDirectiveNoFileComp
4549
},

cmd/internal/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ func RegisterExecCmd(ctx *context.Context, rootCmd *cobra.Command) {
4545
),
4646
Args: cobra.ArbitraryArgs,
4747
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
48+
verbStr := cmd.CalledAs()
49+
verb := executable.Verb(verbStr)
4850
execList, err := ctx.ExecutableCache.GetExecutableList()
4951
if err != nil {
5052
return nil, cobra.ShellCompDirectiveError
5153
}
5254
execIDs := make([]string, 0, len(execList))
5355
for _, e := range execList {
54-
execIDs = append(execIDs, e.ID())
56+
if e.Verb.Equals(verb) {
57+
execIDs = append(execIDs, e.ID())
58+
}
5559
}
5660
return execIDs, cobra.ShellCompDirectiveNoFileComp
5761
},

cmd/internal/workspace.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ func registerSwitchWorkspaceCmd(ctx *context.Context, setCmd *cobra.Command) {
120120
Aliases: []string{"set", "use"},
121121
Short: "Switch the current workspace.",
122122
Args: cobra.ExactArgs(1),
123-
Run: func(cmd *cobra.Command, args []string) { switchWorkspaceFunc(ctx, cmd, args) },
123+
ValidArgsFunction: func(_ *cobra.Command, _ []string, _ string) ([]cobra.Completion, cobra.ShellCompDirective) {
124+
return maps.Keys(ctx.Config.Workspaces), cobra.ShellCompDirectiveNoFileComp
125+
},
126+
Run: func(cmd *cobra.Command, args []string) { switchWorkspaceFunc(ctx, cmd, args) },
124127
}
125128
RegisterFlag(ctx, workspaceCmd, *flags.FixedWsModeFlag)
126129
setCmd.AddCommand(workspaceCmd)

tests/utils/builder/exec.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//nolint:lll
21
package builder
32

43
import (

0 commit comments

Comments
 (0)