Repository navigation
fix: reject an unknown verb under the vm and image groups - #49
Merged
Merged
Conversation
`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.
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.
Problem
A mistyped verb under
vmorimageexits 0 after printing the group's help:An E2E case that ran
cocoon-macos vm gcpassed for a day without collecting anything. cobra returnsflag.ErrHelpfor a non-runnable command before it validates args, and only the root rejects unknown verbs.Args: cobra.NoArgsalone is never reached on a group; the group has to be runnable.Change
vmandimagetakeArgs: cobra.NoArgsand aRunEthat prints the help. This is the same fix as cocoonstack/cocoon#259. The closure is inline because thecliutil.ShowHelphelper added there is not in the pinned cocoon v0.6.8.Verification
Old vs new binary, same arguments:
vm gc,vm nosuchverb,image nosuchverbunknown command "gc" for "cocoon-macos vm"nosuchverbvm,imagegc --help,vm list --helpThe 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,aslandgo test ./cmd/...clean.