Skip to content

cli/command/completion: don't provide duplicate completions#6871

Merged
vvoland merged 1 commit intodocker:masterfrom
thaJeztah:completions_no_dups
Apr 2, 2026
Merged

cli/command/completion: don't provide duplicate completions#6871
vvoland merged 1 commit intodocker:masterfrom
thaJeztah:completions_no_dups

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

When completing for commands that accept multiple arguments, we did not remove suggestions that were already consumed. This could be confusing if there was only 1 suggestion, in which case every <tab> would automatically suggest the same name again:

docker rm -fv magical_lumiere magical_lumiere magical_lumiere

This patch adds a "Unique" helper to wrap a completion func to remove completion results that are already consumed (i.e., appear in "args").

For example:

# initial completion: args is empty, so all results are shown
command <tab>
one two three

# "one" is already used so omitted
command one <tab>
two three

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

shell completions: don't provide completions that were already used.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/completion/functions.go 95.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

vvoland
vvoland previously approved these changes Apr 2, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves shell completion behavior by avoiding suggestions that have already been consumed when completing commands that accept multiple arguments.

Changes:

  • Wrap existing completion functions (images/containers/volumes/networks/env vars and FromList) with a new Unique wrapper.
  • Add a Unique helper that filters completion candidates already present in args.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When completing for commands that accept multiple arguments, we did
not remove suggestions that were already consumed. This could be
confusing if there was only 1 suggestion, in which case every `<tab>`
would automatically suggest the same name again:

docker rm -fv magical_lumiere magical_lumiere  magical_lumiere

This patch adds a "Unique" helper to wrap a completion func to remove
completion results that are already consumed (i.e., appear in "args").

For example:

    # initial completion: args is empty, so all results are shown
    command <tab>
    one two three

    # "one" is already used so omitted
    command one <tab>
    two three

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vvoland vvoland merged commit bbb6311 into docker:master Apr 2, 2026
96 checks passed
@thaJeztah thaJeztah deleted the completions_no_dups branch April 2, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants