8000 context: add shell-completion for context-names by thaJeztah · Pull Request #6016 · docker/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

context: add shell-completion for context-names #6016

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
merged 1 commit into from
Apr 17, 2025

Conversation

thaJeztah
Copy link
Member
@thaJeztah thaJeztah commented Apr 16, 2025

For now, these are not exported and included in the cli/commands/contexts
package; a copy of this also lives in cmd/docker, but we need to find a
good place for these completions, as some of them bring in additional
dependencies.

Commands that accept multiple arguments provide completion, but removing
duplicates:

docker context inspect<TAB>
default  desktop-linux  (current)  production  tcd

docker context inspec default<TAB>
desktop-linux  (current)  production  tcd

docker context inspect default tcd<TAB>
desktop-linux  (current)  production

For "context export", we provide completion for the first argument, after
which file-completion is provided:

# provides context names completion for the first argument
docker context export production<TAB>
default  desktop-linux  (current)  production  tcd

# then provides completion for filenames
docker context export desktop-linux<TAB>
build/           man/                TESTING.md
cli/             docker.Makefile     go.mod
...

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

Add CLI shell-completion for context names

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

Comment on lines 7 to 10
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/context/store"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
Member Author

Choose a reason for hiding this comment

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

Starting to consider if we should have sub-packages here, otherwise cli/command/completion will pull in too many other packages. We can either use cli/command/completion/xxx or alternatively, per command (cli/command/container/completion). Or .. maybe it should live elsewhere 🤔

@codecov-commenter
Copy link
codecov-commenter commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 58.06452% with 13 lines in your changes missing coverage. Please review.

Project coverage is 58.89%. Comparing base (b885722) to head (6fd72c6).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6016      +/-   ##
==========================================
+ Coverage   58.88%   58.89%   +0.01%     
==========================================
  Files         357      358       +1     
  Lines       29940    29961      +21     
==========================================
+ Hits        17631    17647      +16     
- Misses      11329    11333       +4     
- Partials      980      981       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 55 to 59
// ContextNames implements shell completion for context-names.
func ContextNames(dockerCLI contextProvider) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
// TODO(thaJeztah): implement function similar to [store.Names] to (also) include descriptions.
names, _ := store.Names(dockerCLI.ContextStore())
Copy link
Member Author

Choose a reason for hiding this comment

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

Missing some options here to differentiate for different commands;

  • some only accept a single arg
  • some should not include the current context (probably)
  • ideally, we'd be able to also add the context's description (which could be useful, if short that is)

names[i] += "\tcurrent"
}
}
return names, cobra.ShellCompDirectiveNoFileComp
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we have "no space at end" option for positional arguments?

@thaJeztah thaJeztah force-pushed the context_completion branch 3 times, most recently from b04c106 to 1a7d7d6 Compare April 17, 2025 08:11
@thaJeztah thaJeztah self-assigned this Apr 17, 2025
@thaJeztah thaJeztah added this to the 28.1.0 milestone Apr 17, 2025
@thaJeztah thaJeztah marked this pull request as ready for review April 17, 2025 08:12
@thaJeztah thaJeztah requested review from vvoland and Benehiko April 17, 2025 08:16
@thaJeztah
Copy link
Member Author

I have one more small enhancement to not add a space after the limit is reached (and we don't use file-completion after it); let me push

@thaJeztah
Copy link
Member Author

Oh, actually; not sure that works; let's go with what we have here for now

For now, these are not exported and included in the cli/commands/contexts
package; a copy of this also lives in cmd/docker, but we need to find a
good place for these completions, as some of them bring in additional
dependencies.

Commands that accept multiple arguments provide completion, but removing
duplicates:

    docker context inspect<TAB>
    default  desktop-linux  (current)  production  tcd

    docker context inspec default<TAB>
    desktop-linux  (current)  production  tcd

    docker context inspect default tcd<TAB>
    desktop-linux  (current)  production

For "context export", we provide completion for the first argument, after
which file-completion is provided:

    # provides context names completion for the first argument
    docker context export production<TAB>
    default  desktop-linux  (current)  production  tcd

    # then provides completion for filenames
    docker context export desktop-linux<TAB>
    build/           man/                TESTING.md
    cli/             docker.Makefile     go.mod
    ...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the context_completion branch from 1a7d7d6 to 6fd72c6 Compare April 17, 2025 08:32
Comment on lines +1 to +2
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.22
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self; need to update #5868 after this is merged.

@vvoland vvoland merged commit 0e75283 into docker:master Apr 17, 2025
86 of 87 checks passed
@thaJeztah thaJeztah deleted the context_completion branch April 17, 2025 08:42
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
0