Repository navigation
refactor(commands): share InvalidSubcommand error builder across typo sites - #2308
Merged
Merged
Conversation
… 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]>
worktrunk-bot
approved these changes
Apr 19, 2026
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.
Summary
Follow-up from #2306/#2307. Three surfaces all built the same clap
InvalidSubcommanderror 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 withInvalidSubcommand/SuggestedSubcommand/Usagecontext populated.similar_subcommands(name, parent, alias_names) -> Vec<String>— filters visible built-ins + alias names throughdid_you_mean. Moved fromcustom.rs;unknown_step_command_errorused to re-implement this inline.unknown_alias_errorkeeps its uniqueunrecognized subcommand→unrecognized aliasstring 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