Skip to content

Commit f1385df

Browse files
authored
Merge pull request #5968 from albers/completion-service-scale
Improve completion of `service scale` args
2 parents b8034c0 + ee275d5 commit f1385df

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

cli/command/service/scale.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ func newScaleCommand(dockerCli command.Cli) *cobra.Command {
2929
RunE: func(cmd *cobra.Command, args []string) error {
3030
return runScale(cmd.Context(), dockerCli, options, args)
3131
},
32-
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
33-
return CompletionFn(dockerCli)(cmd, args, toComplete)
34-
},
32+
ValidArgsFunction: completeScaleArgs(dockerCli),
3533
}
3634

3735
flags := cmd.Flags()
@@ -117,3 +115,19 @@ func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, ser
117115
}
118116
return response.Warnings, nil
119117
}
118+
119+
// completeScaleArgs returns a completion function for the args of the scale command.
120+
// It completes service names followed by "=", suppressing the trailing space.
121+
func completeScaleArgs(dockerCli command.Cli) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
122+
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
123+
// reuse the existing logic for configurable completion of service names and IDs.
124+
completions, directive := CompletionFn(dockerCli)(cmd, args, toComplete)
125+
if directive == cobra.ShellCompDirectiveError {
126+
return completions, directive
127+
}
128+
for i, v := range completions {
129+
completions[i] = v + "="
130+
}
131+
return completions, directive | cobra.ShellCompDirectiveNoSpace
132+
}
133+
}

0 commit comments

Comments
 (0)