Repository navigation
fix(cli): move command suggestions into hints and drop the dry-run hint on CLI-raised validation errors - #114
AshGodfrey wants to merge 11 commits into
Conversation
…nt on CLI-raised validation errors
There was a problem hiding this comment.
No issues found across 23 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Fixes CLI error output: cobra's unknown-command suggestion block becomes a hint, and the dry-run hint is dropped for CLI-raised validation errors while server 400s keep it. The change is bounded to error messaging, with tests and regenerated SDK.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
Generator Snapshot Testing
Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/120#issuecomment-6222095903 Snapshot results are summarized above. Additional run context is linked for maintainers with access. |
There was a problem hiding this comment.
0 issues found across 5 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Fixes CLI error output by moving cobra's unknown-command suggestions into hints and dropping the misleading dry-run hint for CLI-raised validation errors while keeping it for server 400s. Bounded to error messaging with focused tests and regenerated SDK.
View guided diff | Turn on auto-fix | Re-trigger cubic
…rsing cobra's message
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…lp and completion keep working
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
… the help pointer
There was a problem hiding this comment.
0 issues found across 7 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Focused CLI error-handling bug fix: unknown commands become hint suggestions, the dry-run hint is dropped for CLI-origin validation, with tests and regenerated SDK. Dismissed firstPositional findings are resolved by the new Args-validator path.
View guided diff | Turn on auto-fix | Re-trigger cubic
…command, and document unknown-command hints Only commands that reject positionals (cobra.NoArgs, generated and synthesized groups, the root) have a rejected positional rewritten as an unknown-command error; a hand-written parent that accepts positionals keeps its own validator's message. A real subcommand placed after -- gets a hint to remove the -- instead of being suggested back verbatim. Suggestion lookup no longer leaves SuggestionsMinimumDistance changed on the command. README documents the hint rules and the dry-run gating; tests cover a bare configure, several near matches, and the parent validator case.
There was a problem hiding this comment.
0 issues found across 10 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Bounded CLI error-handling fix: unknown commands become hints/one-line messages, dry-run hint dropped for CLI-origin validation, with tests and regenerated SDK; dismissed firstPositional findings are resolved by the Args-validator rework.
View guided diff | Turn on auto-fix | Re-trigger cubic
Co-authored-by: Ash <AshGodfrey@users.noreply.github.com>
Co-authored-by: Ash <AshGodfrey@users.noreply.github.com>
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…tore the unknown help topic diagnostic The flag error handler only re-validates positionals on commands that reject them, so a parent with its own Args validator reports the flag error even when the failing flag sits between two valid positionals. The built-in help command checks for an unresolved topic itself now that the root no longer relies on root.Find rejecting stray tokens.
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
A flag value after a resolved help topic is no longer reported as an unknown topic. README limits the flag-error positional check to parent commands that reject positionals.
There was a problem hiding this comment.
0 issues found across 6 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Bounded CLI error-handling fix: unknown commands become one-line errors with suggestions as hints, and CLI-origin validation errors drop the dry-run hint; heavily tested, with dismissed firstPositional findings resolved by the Args-validator rework.
View guided diff | Turn on auto-fix | Re-trigger cubic
Why
Two leftovers from the flag-suggestion work in #59.
A mistyped command embedded cobra's whole suggestion block in the error message. In agent mode and
-o jsonthat put raw newlines and tabs inside theerrorandmessagestrings instead of a hint a tool can act on:A typo under a command group got no suggestion at all, because cobra only checks for unknown subcommands at the root. A typo followed by the intended leaf's flags (
errors status-get-erro --status-code 200) failed on the first unknown flag instead, so it got no suggestion either.Every validation error carried "Use --dry-run to preview the request and check parameters", including errors the CLI raised before building any request: a missing required flag, a positional given twice, a bare
configureorauth loginwith no terminal.--dry-runfails those the same way, so the hint cannot apply.What changed
exitcodes.go.stmpl: the root and every synthesized group getcobra.NoArgsas before (the root now explicitly, which retires cobra's root-onlylegacyArgscheck). TheArgswrapper runs the command's own validator first and, only when it rejects and the command has subcommands, reports the first positional throughUnknownSubcommandError. A hand-written parent that accepts positionals keeps accepting them. The message is cobra's one-line form,unknown command "x" for "cli errors". The nearest commands become a hint (Did you mean generate?, orDid you mean one of list, lint?), using cobra's suggestion policy (DisableSuggestions, minimum distance 2). ARun '<command> --help' to list available commandspointer is added and the built-in validation hints are omitted, matching the flag error handler. When a group's flag parse fails after a positional, the flag error handler validates the positionals it already has through the sameArgspath, soerrors status-get-erro --status-code 200reports the command typo rather than the flag. Because the check runs inside cobra's normal execution,--helpafter a typo prints help and shell completion (__complete) is unaffected.classify.go.stmpl: the built-in validation hints drop the dry-run line when the error originated in the CLI (ErrorOriginCLI). Server-side validation (an HTTP 400) keeps it.Before and after, plain output:
Behaviour changes: the suggestion block no longer appears in the error message or on plain stderr; the help hint on unknown commands has new wording; a mistyped root command followed by
--helpprints help with exit 0, as it already did under a group; a suggestion is made when the typo precedes its flags (a typo after an unknown flag still reports the flag). Exit code for the error is unchanged (2).Tests
clierrors_test.go.stmpl: a mistyped command in agent mode yields a single-lineerrorand aDid you mean errors?hint; plain mode prints the same hint and the help pointer without--dry-run; a typo under a group, with and without the leaf's flags, suggests the sibling command;--helpafter a typo prints help;__completestill completes; a name with no near match gets no suggestion. A missing required flag (CLI-origin validation) carries no dry-run hint, while a server 400 still does.exitcodes_test.go.stmpl: the root unknown-command test expects the one-line message.output_test.go.stmpl: unit tests build a real cobra tree and run it throughExecute, covering root typos, typos behind global flags, typos under a group with and without trailing flags, a real name and a typo after--, invocations that resolve cleanly, a parent command that accepts its own positional,--helpafter a typo,__complete, andDisableSuggestions.Public-safety checklist