Skip to content

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

Open
thaJeztah wants to merge 1 commit intodocker:masterfrom
thaJeztah:completions_no_dups
Open

cli/command/completion: don't provide duplicate completions#6871
thaJeztah wants to merge 1 commit intodocker:masterfrom
thaJeztah:completions_no_dups

Conversation

@thaJeztah
Copy link
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)

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>
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 52.38095% with 10 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

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.

2 participants