Skip to content

refactor(commands): share InvalidSubcommand error builder across typo sites - #2308

Merged
max-sixty merged 1 commit into
mainfrom
alias-did-you-mean
Apr 19, 2026
Merged

max-sixty merged 1 commit into
mainfrom
alias-did-you-mean

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

Follow-up from #2306/#2307. Three surfaces all built the same clap InvalidSubcommand error with identical recipes (insert name + suggestions + usage context, render):

  • wt <typo> — unrecognized_subcommand_error (src/commands/custom.rs)
  • wt step <typo> — unknown_step_command_error (src/commands/alias.rs)
  • wt config alias show/dry-run <typo> — unknown_alias_error (src/commands/config/alias.rs)

Consolidate into two shared helpers in src/commands/mod.rs:

  • build_invalid_subcommand_error(anchor, name, suggestions) -> clap::Error — builds the error with InvalidSubcommand / SuggestedSubcommand / Usage context populated.
  • similar_subcommands(name, parent, alias_names) -> Vec<String> — filters visible built-ins + alias names through did_you_mean. Moved from custom.rs; unknown_step_command_error used to re-implement this inline.

unknown_alias_error keeps its unique unrecognized subcommand → unrecognized alias string rewrite and direct-print path, but delegates the clap error construction to the shared builder.

Net: -12 lines, three near-duplicate recipes collapsed to one. All snapshots pass unchanged — the rendered output is identical.

Test plan

  • cargo run -- hook pre-merge --yes — all 3282 tests pass, lints clean, no snapshot drift

… sites

Three surfaces (`wt <typo>`, `wt step <typo>`, `wt config alias show/dry-run
<typo>`) all built the same clap `InvalidSubcommand` error with identical
recipes: insert name + suggestions + usage context, then render. Lift the
construction into `build_invalid_subcommand_error` in `commands/mod.rs`.

Also move the `similar_subcommands` helper (visible built-ins + alias names,
filtered through `did_you_mean`) from `custom.rs` up to `commands/mod.rs` so
`unknown_step_command_error` no longer re-implements it inline.

`unknown_alias_error` keeps its unique `unrecognized subcommand` →
`unrecognized alias` string rewrite and direct-print path, but delegates the
clap error construction to the shared helper.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 3e0320e into main Apr 19, 2026
25 checks passed
@max-sixty
max-sixty deleted the alias-did-you-mean branch April 19, 2026 23:41
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.

2 participants