fix(cli): mistyped group subcommand errors with a suggestion instead of exiting 0 (#75)#175
Merged
Merged
Conversation
…of exiting 0 (#75) `tracebloc data ingst` (and cluster/auth/client typos) printed the group's help and exited 0, silently swallowing the mistake. A parent command with subcommands but no Run/RunE is "not runnable", and cobra short-circuits a non-runnable command to flag.ErrHelp BEFORE it validates args — so the unknown token never reached arg validation. (The issue's suggested `cobra.NoArgs` does NOT fix this: it's an arg validator, never reached on a non-runnable command.) Give the four group commands (data, cluster, auth, client) a RunE=runGroup: a bare `tracebloc <group>` still prints help and exits 0, but a mistyped subcommand is now a hard error (exit 1) with a nearest-match suggestion, matching the "unknown command" wording the root already emits via its default legacyArgs. SuggestionsMinimumDistance=2 drives the hint; SuggestionsFor skips hidden commands, so the Rev-9 hidden `client list` is never suggested. The root command is unchanged — as the parent-less command it already errored on unknown tokens. Tests: internal/cli/group_test.go — unknown-subcommand-errors (across all four groups + the `dataset` alias), nearest-match suggestion, hidden-list not suggested, bare-group-still-helps. The error cases are verified to fail without the fix (unfixed groups print help + exit 0). Full internal suite + vet + gofmt green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
|
Clean, well-tested fix 👍 — root-cause writeup is spot on, and I verified the behavior end-to-end (typo → exit 1 + suggestion, bare group → help/exit 0, hidden Tiny thing: the group message isn't quite "identical" to root's — it appends a |
saadqbal
approved these changes
Jul 8, 2026
Collaborator
|
/fr-pass |
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.
Closes #75.
Problem
tracebloc data ingst(and the same forcluster,auth,client) printed the group's help and exited 0 — a mistyped subcommand looked like success. Verified on develop:data ingst,cluster inf,client lstall exit 0.Root cause (corrects the issue's proposed fix): a parent command with subcommands but no
Run/RunEis not runnable, and cobra short-circuits a non-runnable command toflag.ErrHelpbefore it validates args (command.go:if !c.Runnable() { return flag.ErrHelp }precedesValidateArgs). So the unknown token never reached validation.cobra.NoArgsdoes not fix this — it's an arg validator, never reached on a non-runnable command.Fix
Give the four group commands a
RunE: runGroup(inroot.go):tracebloc <group>→ prints help, exits 0 (unchanged);unknown commandwording the root already emits via cobra's defaultlegacyArgs.SuggestionsMinimumDistance: 2drives the hint;SuggestionsForskips hidden commands, so the Rev-9 hiddenclient listis never suggested. The root command is untouched (it already errored correctly).Tests (
internal/cli/group_test.go)UnknownSubcommand_Errors— all four groups + thedatasetalias, asserts non-zero exit + "unknown command".UnknownSubcommand_Suggests— nearest-match hint (ingst→ingest,inf→info,doctr→doctor).HiddenSubcommand_NotSuggested—client lstmust not surface the hiddenlist.Bare_StillHelpsExitZero— bare group still helps + exits 0.The error cases are verified to fail without the fix. Full
internal/...suite +go vet+gofmtgreen.Targets
develop. Isolated toroot.go+ the four group constructors — no overlap with the open ingest-path PRs.🤖 Generated with Claude Code