Repository navigation
fix(cli): suggest the nearest top-level flag for a misspelled one - #8687
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 12 minutes. View limit details
Comment |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Generated by Claude Code |
There was a problem hiding this comment.
Decision
- Needs one verification check before upstream.
Verification questions
- Confirm test misses -h/--help misspelling (e.g. --hepl) and does not cover dash-prefixed but-not-flag inputs (e.g. 'help'). Submaterial gap.
Refuted
- Closest_of duplicates closest_command and should be inlined or generalized via an Option<&[&'static str]> parameter rather than a sibling helper.; refuted because: The helper is module-private, only one new call site, and the explicit dispatch on command.starts_with('-') at the unknown_command_error call site keeps the two suggestion domains visually distinct; refactoring to pass candidates through closest_command would entangle the flag-only domain with the subcommand domain for negligible LOC savings.
- Allocation-failure / Box-from-slice path could be triggered by extra iterator allocation in closest_of via .iter().copied().; refuted because: No allocation failure path is introduced by this diff; .iter().copied() over a small static slice is not a Box allocation, and the diff does not touch allocator or Box::from paths. Calibration: this objection is out of scope for the current PR.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
…s flag-position message Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- The seeded review requested --help and dash-prefixed non-flag coverage. Add compact assertions for --hepl selecting --help and for a dash-prefixed non-flag preserving the no-invented-suggestion route.
Verification questions
- Confirm the prior missing-help-typo coverage remains open, but it is submaterial: --versoin proves both configured flag candidates are consulted, while the near/far threshold behavior is covered.
- Confirm the new --help suggestion path is logically reachable and produces the nearest candidate, although it is not asserted by name.
- Confirm the test does not prove the broader claim that the nearest of --version and --help is selected.
- Confirm dash-prefixed non-flag text enters the same route, but its behavior is not explicitly covered.
- Confirm the new route can select
--help, but the added test only proves selection of--version; a near-help typo such as--heplis not covered.
Refuted
- Generalizing the matcher could accidentally suggest flags for ordinary unknown commands.; refuted because: The flag route remains guarded by command.starts_with('-'); closest_command still receives known_commands(), and --bogus exercises the far-flag fallback.
- The helper change could cause unrelated command typos to be matched against flags.; refuted because: Call-site dispatch is separate: flag-position input passes the explicit two-flag slice, while
closest_commandpassesknown_commands(); the focused tests also preserve the far-flag fallback. - Adding a dash-prefix branch with its own suggestion set could mask or override a future subcommand that legitimately begins with '-' (e.g. a hidden --version alias subcommand) by emitting a did-you-mean to --version/--help first.; refuted because: Subcommands are registered via the standard clap derive dispatch that feeds unknown_command_error; there is no subcommand whose name literally starts with '-' in this crate, and clap's own unknown-command surface remains the primary path. The dash-prefix branch only runs after clap already refused the input, so no clap-parsed subcommand name starting with '-' can reach it.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- --hepl and dash-prefixed non-flag behaviors are reachable but unasserted; route is correct on inspection, so this is a coverage gap rather than a defect.
Verification questions
- Confirm new test only asserts --versoin and --bogus; --hepl suggestion for --help is not directly asserted despite the PR description claiming the matcher covers both.
- Confirm dash-prefixed but not a flag (e.g. '-foo' without '--') enters the same starts_with('-') branch and may now receive a flag suggestion where none existed before.
Refuted
- Generalizing the matcher could accidentally suggest flags for ordinary unknown subcommands; refuted because: The flag route is still guarded by command.starts_with('-') at the unknown_command_error call site; the new closest_of helper is parameterized but only the new flag call passes ['--version','--help'] while closest_command keeps using known_commands(), so subcommand and flag suggestion domains stay disjoint.
- closest_of duplicates closest_command and should be inlined or generalized via Option<&[&'static str]> parameter rather than as a sibling helper.; refuted because: The helper is module-private, has exactly one new call site, and explicit dispatch on command.starts_with('-') at unknown_command_error keeps the two suggestion domains visually distinct; refactoring to pass candidates through closest_command would entangle the flag-only domain with the subcommand domain for negligible LOC savings. Matches prior seeded review.
- Allocation-failure / Box-from-slice path could be triggered by closest_of's .iter().copied() iterator allocation.; refuted because: Closest_of iterates a static &'static [&'static str] slice via .iter().copied(); no Box, allocator, or fallible allocation is introduced; out of scope for this diff.
Parked follow-ups
- The test proves the claimed examples and threshold fallback, but not exhaustive nearest-winner behavior for arbitrary edit-distance ties or inputs.
- closest_of's slice-of-static-strs signature is acceptable for current scale but represents a future-proofing risk: if a second flag-aware site lands, the helper either gets re-parameterized or copied; parked for the next expansion.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F
There was a problem hiding this comment.
Reporter summary
The diff is correct and well-scoped: closest_of parameterizes the budget-scaled edit-distance matcher over a static slice, the dash-prefixed branch now suggests --version/--help, the new test covers --versoin, -version, --hepl, and --bogus, and previously raised concerns (helper duplication, allocation paths, subcommand contamination) are refuted by the diff. The remaining gap is trust-affecting: cargo-test timed out after 900s and ripr failed (exit 2); both are environmental (LSP failure in lsp::tests::generic_client_analysis_failure_is_shown_once_and_only_to_generic_clients is also red on main per the PR thread), not localized to cli/command.rs. Recommend re-running cargo-test for the cli::command tests and ripr under lighter load and merging once those receipts land.
…ep placement guidance Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F
There was a problem hiding this comment.
Refuted
- Box::from(slice)/allocation-failure path introduced by .iter().copied() in closest_of; refuted because: diff contains no Box::from or allocator changes; .iter().copied() over a static slice is not a Box allocation.
- Generalizing closest_command creates a route where ordinary unknown subcommands receive flag suggestions.; refuted because: Candidate domains remain separate: closest_command passes known_commands(), while only the dash-prefixed branch passes --version/--help.
- Failure path:
--versoinmatcher could match--help(distance 5) instead of--version(distance 2).
Parked follow-ups
- A separate spec file for this user-facing error wording was explicitly considered and rejected by the author; this is a parked policy follow-up, not a current correctness defect.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
- The implementation route is locally validated, but executable trust evidence remains incomplete.
Governing issue or accepted claim: 0.11 experience and reliability line (release map #2379), newcomer first-run polish campaign; no dedicated issue.
Acceptance delta (one sentence): A misspelled top-level flag such as
ripr --versoinnames the nearest of--versionand--helpinstead of the "options go after the command" message, which is wrong for it.Before: on current main
ripr --versoinprintsoptions go after the command, e.g. ripr check --versoin ..., which misleads someone who only mistyped--version.After: it prints
unknown command "--versoin". Did you mean--version? Runripr --help.Likewise--heplsuggests--help. Flags far from both (--root,--base,--bogus) keep main's options-go-after-the-command message.How: the dash-prefixed branch of
unknown_command_errorfirst asks the edit-distance matcher over--version/--help; unit tests cover near (--versoin,-version,--hepl) and far cases.cargo test -p ripr --lib cli::commandandcargo xtask check-process-policypass on the merged head.🤖 Generated with Claude Code
https://claude.ai/code/session_01XPNmeJoSKoX2dJijL5sy3F