Skip to content

feat: give clap usage errors a runnable next command - #7

Merged
zawakin merged 1 commit into
mainfrom
feature/actionable-parse-errors
Jun 29, 2026
Merged

feat: give clap usage errors a runnable next command#7
zawakin merged 1 commit into
mainfrom
feature/actionable-parse-errors

Conversation

@zawakin

@zawakin zawakin commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes the last remaining gap from the CLI help re-evaluation (rep 9.5/10 → aiming for full marks on Rule 13).

The previous PR (#6) made runtime errors actionable (not-a-git-repo, dirty tree, stale plan), but clap's parse errors — unknown subcommand, missing argument, bad flag — still ended at clap's default For more information, try '--help' with no runnable next step.

What changed

Parse via try_parse() and handle usage errors ourselves:

  • Runnable Try: line, contextual to the subcommand the user was reaching for:
    $ rep scan
    error: the following required arguments were not provided:
      <TOKEN>
    ...
    → Try:  rep scan old_name
    
    clap's own "did you mean" tips are preserved.
  • --json stays JSON: under --json a usage error emits the standard rep.error.v1 envelope (kind: invalid_arguments), so an agent on the primary interface never hits a non-JSON failure.
  • Exit code 10, not clap's default 2: rep already publishes 2 as "no matches" (a successful empty scan), so usage errors now use 10 (invalid_arguments) — agents can distinguish a clean empty scan from a mistyped command.
  • --help / --version untouched — still rendered by clap, exit 0. rep with no args still prints full help (which now carries the EXAMPLE on-ramp).

Testing

mise run rep:verify passes. Added 3 tests: unrecognized subcommand → 10, missing required arg → 10, and usage error under --json → valid rep.error.v1 envelope.

🤖 Generated with Claude Code

The previous help pass made runtime errors (not-a-git-repo, dirty tree,
stale plan) actionable, but clap's own parse errors -- unknown command,
missing argument, bad flag -- still ended at the default "For more
information, try '--help'" footer with no next step.

Parse via try_parse and handle usage errors ourselves:

- Append a 'Try:' line with a copy-pasteable command for whichever
  subcommand the user was reaching for (e.g. 'rep scan' missing its token
  -> 'Try:  rep scan old_name'). clap's own "did you mean" tips are kept.
- Under --json, emit the standard rep.error.v1 envelope instead, so an
  agent on the primary interface never gets a non-JSON failure.
- Exit usage errors with code 10 (invalid_arguments) rather than clap's
  default 2, which rep already publishes as "no matches" -- agents must
  distinguish a clean empty scan from a mistyped command.
- --help/--version remain untouched (rendered by clap, exit 0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zawakin zawakin self-assigned this Jun 29, 2026
@zawakin
zawakin merged commit 09fa8fe into main Jun 29, 2026
7 checks passed
@zawakin
zawakin deleted the feature/actionable-parse-errors branch June 29, 2026 10:07
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