fix(cli): completion exit=1 + instant version alias#21
Merged
mastermanas805 merged 1 commit intoMay 30, 2026
Merged
Conversation
… (BUG-CLI-016, BUG-CLI-041)
BUG-CLI-016: cobra's default `completion` parent command prints help
and exits 0 when invoked with no shell argument. Wrong contract for
CI/wrapper scripts — "no shell selected" is a usage error, not
success. Force-init the default completion subtree via
InitDefaultCompletionCmd() (cobra normally adds it lazily in
Execute()), then stamp a RunE that returns a plain error so
ExitCodeFor classifies as ExitGeneric (1). Sub-shells (`completion
bash`, etc.) keep their original RunE — only the bare invocation
changes.
BUG-CLI-041: many CLIs accept both `version` and `--version`. Cobra
wires --version via rootCmd.Version, but `instant version` returned
"unknown command 'version'" with exit=1 — confusing for users
muscle-memorying git/node version patterns. Register an explicit
`version` alias that prints the same one-line output cobra emits for
--version.
Coverage block (rule 17):
Symptom: `instant completion` exit=0; `instant version` => unknown command
Enumeration: cobra auto-adds ONE completion parent + N shell
sub-commands (bash, zsh, fish, powershell).
Sites found: completion parent (1), shell sub-commands (4) ×
un-touched. version alias (0 → 1 new).
Sites touched: 1 RunE override on the parent, 0 sub-shell touches.
Coverage tests:
TestCompletion_NoShellArg_ReturnsError — pins exit code + message
TestCompletion_EveryShellSubcommandStillSucceeds — registry-iterates
over {bash,zsh,fish,powershell} so a future cobra-side addition
that escapes the override is caught.
TestVersion_AliasExitsZero / TestVersion_AliasExtraArgsRejected —
pins exit code + arg contract.
Live verified: pending CI auto-deploy (rule 14 SHA check on `instant
--version` after release).
cmd/ package coverage 95.5%; init() 100%.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
instant completion(no shell arg) used to print help and exit 0 — wrong contract for CI scripts. Now returns a non-zero exit with a clear "shell argument required (bash | zsh | fish | powershell)" error.instant versionnow works as an alias forinstant --version(was previously rejected with "unknown command 'version'").Sub-shells (
completion bash/zsh/fish/powershell) are unchanged — they still emit the script and exit 0.Coverage block (rule 17)
Test plan
go build ./...cleango vet ./...cleango test ./...all passinstant completionexits 1;instant completion bashexits 0;instant versionexits 0Inbox: BUG-CLI-016, BUG-CLI-041