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:
Mohammed Aminu Futa
2025-02-11 12:55:22 +00:00
parent 516e822d4c
commit a656dfd409
10 changed files with 13 additions and 10 deletions

View File

@ -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