Restrict completion for some commands with a limit paramter for ImageNames
Previously, multiple suggestions were provided when completing commands like `run`, `history` and `push`. This change limits completion to a single suggestion for the above and 2 suggestions for `tag` Signed-off-by: Mohammed Aminu Futa <mohammedfuta2000@gmail.com>
This commit is contained in:
@ -27,8 +27,11 @@ type APIClientProvider interface {
|
||||
}
|
||||
|
||||
// ImageNames offers completion for images present within the local store
|
||||
func ImageNames(dockerCLI APIClientProvider) ValidArgsFn {
|
||||
func ImageNames(dockerCLI APIClientProvider, limit int) ValidArgsFn {
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if limit > 0 && len(args) >= limit {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
list, err := dockerCLI.Client().ImageList(cmd.Context(), image.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveError
|
||||
|
||||
Reference in New Issue
Block a user