Repository navigation
Conversation
`#[command(external_subcommand)]` (added in #2054 for `wt-<name>` dispatch) captures every unknown subcommand, so clap's native `InvalidSubcommand` error path was dead — `wt s` printed a custom git-style line instead of clap's formatted error with suggestions and Usage block. Synthesize a real `clap::Error{InvalidSubcommand}` when no `wt-<name>` binary is on PATH and route it through `enhance_and_exit_error`, so the output matches what clap would have produced: error: unrecognized subcommand 's' tip: some similar subcommands exist: 'step', 'switch' Usage: wt [OPTIONS] [COMMAND] For more information, try '--help'. Nested-subcommand hints (`wt squash` → `wt step squash`) now layer on top of clap's error via the same path instead of a separate branch, so all unrecognized subcommands flow through one code path. Swap Levenshtein for Jaro-Winkler > 0.7 to match clap's internal `did_you_mean`, so short names like `s` get suggestions that match short-prefix typos. Exit code is now 2 (clap standard), matching pre-#2054 behavior. Co-Authored-By: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Apr 14, 2026
Follow-up to #2212. That PR restored clap-native errors for top-level `wt <typo>`; this one applies the same treatment one level down so `wt step <typo>` reads identically. The three custom `bail!` branches in `step_alias` (`Unknown step command X — perhaps Y?`, `Unknown step command X (no aliases configured)`, `Unknown alias X (available: …)`) are replaced by a synthesized `clap::Error{InvalidSubcommand}` routed through `enhance_and_exit_error`. Output now reads: ``` error: unrecognized subcommand 'sqush' tip: some similar subcommands exist: 'squash', 'push' Usage: wt step <COMMAND> For more information, try '--help'. ``` Exit code is 2 (clap convention) instead of 1. User-configured aliases are fed into `SuggestedSubcommand`, so a typo like `wt step deplyo` still suggests `deploy` when `deploy` is a user alias — `wt step u` suggests `up` (user alias) alongside `push`/`squash`. The full alias list isn't crammed into the error; `wt step --help` (already augmented by `augment_step_help`) is the discovery surface, and the `Usage:` block points there. Trade-off considered: the old `Unknown alias X (available: …)` wording matched the "alias I configured" mental model better. Decided consistency wins — `tip:` covers typo-suggestion equally well, and a single error format for `wt <typo>` and `wt step <typo>` is easier to learn than two. Verified with `cargo run -- hook pre-merge --yes`: 3181 tests pass, no lint or doc warnings. Five snapshot updates in `tests/snapshots/integration__integration_tests__step_alias__*` reflect the new format. Co-authored-by: Claude <[email protected]>
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.
#[command(external_subcommand)](added in #2054 forwt-<name>dispatch) captures every unknown subcommand, so clap's nativeInvalidSubcommanderror path was dead —wt sprinted a custom git-style line instead of clap's formatted error with suggestions and Usage block.This PR synthesizes a real
clap::Error{InvalidSubcommand}when nowt-<name>binary is on PATH and routes it throughenhance_and_exit_error, so the output matches what clap would have produced:```
error: unrecognized subcommand 's'
tip: some similar subcommands exist: 'step', 'switch'
Usage: wt [OPTIONS] [COMMAND]
For more information, try '--help'.
```
Nested-subcommand hints (
wt squash→wt step squash) now layer on top of clap's error via the same path instead of a separate branch, so all unrecognized subcommands flow through one code path.Swap Levenshtein for Jaro-Winkler > 0.7 to match clap's internal
did_you_mean, so short names likesget suggestions that match short-prefix typos.Exit code is now 2 (clap standard), matching pre-#2054 behavior.
Test plan
cargo run -- s/siwtch/squash/ unknown → verified output and exit codeswt hook pre-merge --yes(full test suite, 3178 tests)tests/integration_tests/external.rs