Repository navigation
fix(cli): report an unknown subcommand before an empty positional - #6235
Draft
shunxinyi-ljs wants to merge 1 commit into
Draft
shunxinyi-ljs wants to merge 1 commit into
shunxinyi-ljs wants to merge 1 commit into
Conversation
`weknora tag create "$NAME"` with NAME unset failed as "argument 3 is empty": the input-hygiene gate runs in PersistentPreRunE, which cobra executes before dispatching to the group command, so the empty positional was reported instead of the mistyped command - the same line without the empty value reports `input.unknown_subcommand`. Resolve the subcommand first and let the hygiene gate handle the command that actually runs.
This branch has not been deployed
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.
Description
weknora doc viwe "$ID"withIDunset reportedargument 2 is empty, not the mistyped subcommand:The input-hygiene gate runs in the root
PersistentPreRunE, which cobra executes before a group command'sRunEreports the unknown subcommand, so an empty positional masked the real mistake. Two runs of the same command line produced two different errors depending on whether the variable captured a value.PersistentPreRunEnow resolves the subcommand first: if the command has children andargs[0]is not one of them, it returnsunknownSubcommandRunE(the same typed error, hint andretry_argvtheRunEproduces) before hygiene runs. Hygiene is unchanged for every command that actually resolves.Type of Change
Related Issue
Fixes #6234
Testing
TestUnknownSubcommand_WinsOverEmptyArgumentincmd/root_unknown_subcommand_test.go: executestag create ""in-process and assertsinput.unknown_subcommandnaming"tag".cmd/root.go: on the pre-patch tree the same test fails withcode = input.invalid_argument, want input.unknown_subcommand (argument 3 is empty); with the patch it passes.cd cli && go test ./cmd/ ./internal/cmdutil/ ./acceptance/contract/— passes.doc viwe ""andkb veiw ""now report the unknown subcommand with the "did you mean" hint;doc viwe xis unchanged.gofmt -lclean;git diff --checkclean.Checklist
git diff --check origin/main...HEADpassesgofmt)golangci-lintis not installed here; CI covers it)internal/agent/toolsneeds cgo +pg_query, which this host cannot build; unrelated to this diff)Screenshots / Recordings
Not a UI change.