-
Notifications
You must be signed in to change notification settings - Fork 2.2k
completion: add completion for swarm "--filter" flags #7124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thaJeztah
merged 1 commit into
docker:master
from
JessThrysoee:completion-swarm-filters
Jul 27, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package node | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/docker/cli/internal/test" | ||
| "github.com/spf13/cobra" | ||
| "gotest.tools/v3/assert" | ||
| ) | ||
|
|
||
| func TestCompleteNodePsFilters(t *testing.T) { | ||
| tests := []struct { | ||
| doc string | ||
| toComplete string | ||
| expected []string | ||
| directive cobra.ShellCompDirective | ||
| }{ | ||
| { | ||
| doc: "no input offers the filter keys", | ||
| toComplete: "", | ||
| expected: []string{"desired-state=", "id=", "label=", "name="}, | ||
| directive: cobra.ShellCompDirectiveNoSpace, | ||
| }, | ||
| { | ||
| doc: "desired-state values", | ||
| toComplete: "desired-state=", | ||
| expected: []string{"desired-state=running", "desired-state=shutdown", "desired-state=accepted"}, | ||
| directive: cobra.ShellCompDirectiveNoFileComp, | ||
| }, | ||
| { | ||
| doc: "label offers no values", | ||
| toComplete: "label=", | ||
| expected: nil, | ||
| directive: cobra.ShellCompDirectiveNoFileComp, | ||
| }, | ||
| { | ||
| doc: "unknown key falls back to the filter keys", | ||
| toComplete: "bogus=", | ||
| expected: []string{"desired-state=", "id=", "label=", "name="}, | ||
| directive: cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.doc, func(t *testing.T) { | ||
| cli := test.NewFakeCli(&fakeClient{}) | ||
| completions, directive := completeNodePsFilters(cli)(newPsCommand(cli), nil, tc.toComplete) | ||
| assert.DeepEqual(t, completions, tc.expected) | ||
| assert.Equal(t, directive, tc.directive) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the old bash-completion couldn't easily do this because the CLI does not have a comment to list tasks, but as a follow up we could look if we actually could use the API client for this;
cli/cli/command/node/ps.go
Lines 75 to 82 in 4f7c07c
Definitely OK for a follow-up though, no need to cramp it into this PR.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label=a TaskList/ServiceList call and pluck the label from the Itemsname=a little heavier with multiple api calls, should system.taskNames be made available for this?id=probably not as useful, but also just a TaskList callBut I think you are right, this feels like a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! No need to do it for this one; I was only glancing over the changes (at a glance they look great! but will have a closer look tomorrow), and was thinking out loud to see if we could fill in the remaining bits.
But indeed; more than fine for a follow-up, so that we can see if it makes sense (outweigh the overhead against how much it improves).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(marked it "unresolved" so that it stays visible, but no need to fix)