Skip to content

fix: reject an unknown verb under the vm and image groups - #49

Merged
CMGS merged 1 commit into
masterfrom
cli/reject-unknown-verb
Sep 23, 2026
Merged

CMGS merged 1 commit into
masterfrom
cli/reject-unknown-verb

Conversation

@CMGS

@CMGS CMGS commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Problem

A mistyped verb under vm or image exits 0 after printing the group's help:

$ cocoon-macos vm gc; echo $?      # gc is a top-level command
Manage macOS VMs
...
0

An E2E case that ran cocoon-macos vm gc passed for a day without collecting anything. cobra returns flag.ErrHelp for a non-runnable command before it validates args, and only the root rejects unknown verbs. Args: cobra.NoArgs alone is never reached on a group; the group has to be runnable.

Change

vm and image take Args: cobra.NoArgs and a RunE that prints the help. This is the same fix as cocoonstack/cocoon#259. The closure is inline because the cliutil.ShowHelp helper added there is not in the pinned cocoon v0.6.8.

Verification

Old vs new binary, same arguments:

invocation before after
vm gc, vm nosuchverb, image nosuchverb rc 0, help rc 1, unknown command "gc" for "cocoon-macos vm"
nosuchverb rc 1 rc 1
vm, image rc 0, help rc 0, help
gc --help, vm list --help rc 0 rc 0

The only help-text change is one extra usage line on a group (cocoon-macos vm [flags]).

make lint (linux + darwin) 0 issues, make fmt-check, go vet ./... on both GOOS, asl and go test ./cmd/... clean.

`cocoon-macos vm gc` (gc is top-level) and any other mistyped verb under vm
or image printed the group's help and exited 0, so a script calling it passed
without running anything. cobra returns ErrHelp for a non-runnable command
before it validates args, so both groups now take cobra.NoArgs plus a RunE
that prints the help: an unknown verb fails with
`unknown command "gc" for "cocoon-macos vm"`, the bare group still prints its
help and exits 0.
@CMGS
CMGS merged commit b25403f into master Sep 23, 2026
3 checks passed
@CMGS
CMGS deleted the cli/reject-unknown-verb branch September 23, 2026 03:42
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