Skip to content

fix(cli): completion exit=1 + instant version alias#21

Merged
mastermanas805 merged 1 commit into
masterfrom
fix/cli-completion-exit-and-version-alias-2026-05-30
May 30, 2026
Merged

fix(cli): completion exit=1 + instant version alias#21
mastermanas805 merged 1 commit into
masterfrom
fix/cli-completion-exit-and-version-alias-2026-05-30

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • BUG-CLI-016: 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.
  • BUG-CLI-041: instant version now works as an alias for instant --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)

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).

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./... all pass
  • cmd/ package coverage 95.5%; root.go::init() 100% covered
  • manual: instant completion exits 1; instant completion bash exits 0; instant version exits 0
  • Release: next CLI version published via release workflow

Inbox: BUG-CLI-016, BUG-CLI-041

… (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>
@mastermanas805 mastermanas805 merged commit 93862ab into master May 30, 2026
10 checks passed
@mastermanas805 mastermanas805 deleted the fix/cli-completion-exit-and-version-alias-2026-05-30 branch May 30, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant