Repository navigation
cmd/docker: fail on unknown command with --version - #7408
Merged
vvoland merged 1 commit intoOct 19, 2026
Merged
Conversation
vvoland
previously approved these changes
Oct 19, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Collaborator
|
Please squash into one commit |
Running "docker nonexistent --version" printed the CLI version and
exited 0, so it couldn't be used to check whether a command or plugin
is available. Without "--version" the same invocation fails with an
"unknown command" error.
When no built-in command or plugin matches, runDocker falls through to
executing the root command, and cobra handles the "--version" flag
before the root command reports the unknown command. Unset the root
command's version in that fallback, so the standard unknown-command
error is returned.
A global "--version" flag ("docker --version nonexistent") is parsed
before the command name and still prints the version, as do
"docker --version" and "docker nonexistent --help".
Signed-off-by: Nimesh Kulkarni <167794819+GitNimay@users.noreply.github.com>
GitNimay
force-pushed
the
3833-unknown-command-version-flag
branch
from
October 19, 2026 14:09
b1fcfb6 to
e08aa72
Compare
Contributor
Author
vvoland
approved these changes
Oct 19, 2026
Collaborator
|
Thanks! |
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.
docker missing-subcommand --version#3833Summary
docker nonexistent --versionprinted the CLI version and exited 0, so it couldn't be used to check whether a command or plugin (for exampledocker compose) is installed. Without--versionthe same invocation fails withunknown command.When no built-in command or plugin matches,
runDockerfalls through to executing the root command. Cobra handles--versionbefore the root command'sRunEreports the unknown command. This PR unsets the root command'sVersionin that fallback, so the standard unknown-command error is returned. Plugin hooks still run, since the normal execution path is unchanged.Before:
After:
Unchanged:
docker --version/docker -vstill print the version, including when--versionis passed as a global flag before an unknown argument (docker --version foo, covered byTestCliPluginsVersion).docker nonexistent --helpstill prints the top-level help (covered byTestNonexistingHelp).--version(e.g.docker compose --version).Added
TestNonexistingVersiontoe2e/cli-plugins, covering both--versionand-v.Release notes (optional)