contrib/completion/zsh: add CLI plugin completion support#6811
Open
4RH1T3CT0R7 wants to merge 1 commit intodocker:masterfrom
Open
contrib/completion/zsh: add CLI plugin completion support#68114RH1T3CT0R7 wants to merge 1 commit intodocker:masterfrom
4RH1T3CT0R7 wants to merge 1 commit intodocker:masterfrom
Conversation
7409672 to
12382f1
Compare
Previously, the zsh completion script could list Docker CLI plugin commands (compose, buildx, etc.) via __docker_commands(), but had no handler in __docker_subcommand() for them. This meant that while "docker <TAB>" would show "compose" as an option, "docker compose <TAB>" produced no completions. Add support for CLI plugin completion by invoking the plugin binary's Cobra __completeNoDesc protocol, similar to how the bash completion already handles this. The implementation handles all six Cobra ShellCompDirective values: - Error (1): abort completion - NoSpace (2): suppress trailing space - NoFileComp (4): suppress file fallback - FilterFileExt (8): filter files by extension - FilterDirs (16): complete directories only - KeepOrder (32): preserve completion ordering Additionally: - Plugin paths are cached using zsh's _store_cache/_retrieve_cache with the same 1-hour TTL policy as __docker_commands - ActiveHelp markers are displayed as informational text - Literal colons in completions are escaped for _describe - --flag=<TAB> completions propagate the flag prefix correctly - Words are truncated to CURRENT for backward cursor movement Closes: docker#6231 Signed-off-by: 4RH1T3CT0R7 <iprintercanon@gmail.com>
12382f1 to
c765db0
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
- What I did
Added zsh completion support for Docker CLI plugins (compose, buildx, scout, etc.) by implementing the Cobra
__completeNoDescshell completion protocol.Previously,
docker <TAB>would list plugin commands, butdocker compose <TAB>produced no completions because__docker_subcommand()had no handler for CLI plugins.- How I did it
Added three components to
contrib/completion/zsh/_docker:__docker_cli_plugin_path()— discovers plugin binary paths fromdocker infooutput, with results cached using zsh's_store_cache/_retrieve_cache(1-hour TTL matching__docker_commands)__docker_complete_cli_plugin()— invokes the plugin binary with__completeNoDescand processes the response, handling all six CobraShellCompDirectivevalues:A
(*)fallback case in__docker_subcommand()that delegates to the plugin binary when the command matches a known plugin.Additional details:
compadd -x_describeseparator--flag=<TAB>completions propagate the flag prefix correctlyCURRENTfor backward cursor movement supportvendor/github.com/spf13/cobra/zsh_completions.goand the existing bash plugin completion incontrib/completion/bash/docker- How to verify it
source contrib/completion/zsh/_dockerdocker compose <TAB>— should show compose subcommandsdocker compose up --<TAB>— should show compose flagsdocker buildx build <TAB>— should show buildx completions- Human readable description for the release notes
Closes #6231