Repository navigation
Smart routing for alias arguments + dry-run routing display - #2304
Merged
Merged
Conversation
… --var
The alias argument parser now uses the template's referenced variables as
the binding signal: `--KEY=VALUE` binds to `{{ KEY }}` iff the template
references it, else forwards as a positional. The `--` literal-forward
escape stops routing (including built-in `--yes`/`--dry-run`), and the
`--var KEY=VALUE` / `--var=KEY=VALUE` special cases are removed — they're
just `--KEY=VALUE` under the new grammar.
Before: `wt rm my-branch` errored ("Unexpected argument"). Users had to
pre-declare vars via `--var` even though templates already declare which
variables they use.
After: Every post-name token has a valid destination — bound var or
positional forwarded into `{{ args }}`. No token is ever silently dropped.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
# Conflicts: # src/commands/alias.rs # src/config/mod.rs # src/main.rs
# Conflicts: # src/commands/alias.rs # tests/integration_tests/step_alias.rs
Follow-up to the main-branch merge that combined PR D (template-ref routing) with #2290 (post-alias --yes cutover). Under the new grammar, `--yes` after an alias name falls through to the positional branch and forwards into `{{ args }}` — it doesn't error as "Unknown flag" (main's expectation) nor does it skip approval (its old semantics). - Migrate four PR-D tests from inline `--yes` to global `-y` via `make_snapshot_cmd_with_global_flags` - Rename `test_post_alias_yes_no_longer_supported` to `test_post_alias_yes_does_not_skip_approval` and assert the approval prompt surfaces instead of an unknown-flag error Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`--KEY VAL` now consumes two tokens whenever a next token exists, mirroring the atomic `--KEY=VALUE` form: bind if KEY is referenced, else forward both as positionals. Removes the previous "next starts with --" safety check. Tradeoff: `--env --dry-run` with `env` referenced binds `env=--dry-run` rather than activating dry-run. Workaround is the `=` form or putting flags before the bound key. Co-Authored-By: Claude <[email protected]>
# Conflicts: # docs/content/extending.md # skills/worktrunk/reference/extending.md # src/commands/alias.rs # tests/integration_tests/approval_ui.rs # tests/integration_tests/step_alias.rs # tests/snapshots/integration__integration_tests__step_alias__alias_double_dash_stops_routing.snap # tests/snapshots/integration__integration_tests__step_alias__step_alias_binds_space_separated_var.snap # tests/snapshots/integration__integration_tests__step_alias__step_alias_with_var.snap
# Conflicts: # src/config/expansion.rs
Collapse the five-row routing table to two rows (bound vs forwarded), trim the space-form surprise note to one sentence, and remove the "Escaping with --" subsection — the table row covers the mechanism and `--` is a POSIX convention. Co-Authored-By: Claude <[email protected]>
# Conflicts: # docs/content/extending.md # skills/worktrunk/reference/extending.md # src/commands/alias.rs # tests/snapshots/integration__integration_tests__step_alias__step_alias_binds_space_separated_var.snap
Drop the dry-run forwarding/vars.* caveat paragraph (the bullet above covers the main point) and the minijinja-parses-as-subtraction explanation (behavior is self-evident from the example). Co-Authored-By: Claude <[email protected]>
Runtime polish on top of the smart-routing parser: - Parser now returns `(AliasOptions, Vec<String>)`; callers emit the warnings before execution. Keeps `parse` pure so tests can assert on both halves. - Warn when `--KEY VALUE` binds VALUE to a `--`-prefixed next token — almost always a typo where `--KEY=--VALUE` was meant. - Warn in `wt config alias show/dry-run` when the alias name shadows a top-level built-in (reachable only via `wt step <name>`). - `wt config alias dry-run` prints `# bound:` and `# args:` routing comments above the rendered command so users can see how each token was interpreted. Docs: rewrite the aliases section — concrete fly preview-env example, "Passing values" renamed from the opaque "How arguments are routed", routing mechanism moves above the introspection tools. Restore the `up` rebase recipe and add a `since-main` alias example. New tests: duplicate-key precedence, footgun warning, shadow warning. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Apr 19, 2026
These were superseded by tests with parallel names taken from main during the merge — CI's `cargo insta test --unreferenced reject` caught them after the branch pushed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Worktrunk Bot <[email protected]>
…adow warning Review cleanup found two user-visible issues in the alias subsystem: - `wt config alias dry-run --help` referenced `--var`, which was retired; aliases only accept `--KEY=VALUE`. This text propagates to docs via test_command_pages_and_skill_files_are_in_sync. - `warn_if_shadowed` used backticks + format!, bypassing the <bold> styling other warnings use for commands/identifiers. Co-Authored-By: Claude <[email protected]>
Round 2 review follow-ups on PR #2304: - Intercept `--help`/`-h` in alias dispatch (both top-level and `wt step` paths). Print a hint pointing at `wt config alias show/dry-run` rather than silently forwarding the flag into `{{ args }}`. `wt <alias> -- --help` still forwards, documented alongside. Tests cover both paths. - Drop the "invoke via `wt step <name>`" suggestion from the shadow warning — the step path exists as an escape, not something to advertise. A TODO on `step_alias` flags it for deprecation consideration. - `--KEY --VALUE` footgun warning now shows the user's typed form (`--my-env`) throughout, not the canonicalized template name (`my_env`). - New parser test for `--foo=a=b=c` (multi-`=` value) to lock in `split_once('=')` behavior. - Snapshot test for `wt config alias dry-run <shadowed>`, mirroring the existing `show` coverage. - Snapshot test for retired `--dry-run` reaching `step_alias` (shared parser already handled it; this pins the dispatch route). - Docs: `{{ args }}` now appears in the multi-step pipeline example, and a sentence notes every step sees the same args. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 19, 2026
The help-hint output in `emit_alias_help_hint` used bare `println!`, which the stdout-guard test rejects — `src/commands/` code must use `worktrunk::styling::println` (or be explicitly allowlisted for stdout). Switch to the styling re-export and collapse the four `println!` calls into a single multiline invocation. Add `alias.rs` to `STDOUT_ALLOWED_PATHS` since the substring scanner can't distinguish `worktrunk::styling::println!` from `std::println!` — `--help` output conventionally goes to stdout, so this file belongs in the allowlist alongside `config/alias.rs`. Co-Authored-By: Claude <[email protected]>
This was referenced Apr 19, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 19, 2026
…2306) ## Summary Four alias-typo surfaces rendered in two formats. After #2304's round-2 review, this aligns `config alias show/dry-run` with `wt <typo>` and `wt step <typo>`. Before: - `wt deplyo` / `wt step deplyo` → clap-native `error: unrecognized subcommand 'X'` + `tip: …`, exit 2 - `wt config alias show deplyo` / `dry-run deplyo` → custom anyhow gutter `✗ unknown alias 'X'` + gutter bars, exit 1 After (all four surfaces): - Same clap-native `error:` / `tip:` / `Usage:` layout, exit 2 - `config alias show/dry-run` say "alias" / "aliases" instead of "subcommand" / "subcommands" — the positional is an alias name, not a subcommand ## How `unknown_alias_error` builds a real `clap::Error` with `ErrorKind::InvalidSubcommand`, renders it through clap, then substitutes clap's fixed phrases (`unrecognized subcommand` → `unrecognized alias`, `similar subcommands` → `similar aliases`, `similar subcommand` → `similar alias`). Writing through `anstream::AutoStream::auto(stderr)` gets NO_COLOR / TTY detection and clap's singular-vs-plural phrasing automatically. Returns `WorktrunkError::AlreadyDisplayed { exit_code: 2 }` so `main`'s `finish_command` still runs `terminate_output` + `write_if_verbose`. Substitutions are deliberately narrow — an alias name or typo containing the literal substring `subcommand` (e.g. `my-subcommand`) is echoed verbatim, not mangled. ## Changes - `src/commands/config/alias.rs`: replace the anyhow-returning `unknown_alias_error` (exit 1, custom gutter) with a clap-rendering version (exit 2, matches clap-native surfaces). Parameterized by `sub` so the Usage line reads `wt config alias <sub> <NAME>`. - New tests: `test_config_alias_dry_run_unknown_suggests`, `test_config_alias_show_unknown_singular_suggestion`, `test_config_alias_show_unknown_preserves_user_input`. - Refreshed `test_config_alias_show_unknown_suggests` and `test_config_alias_show_unknown_no_suggestions` snapshots. ## Test plan - [x] `cargo test --test integration step_alias` (58 pass) - [x] `cargo test --lib --bins` (598 pass) - [x] `pre-commit run --all-files` clean - [x] Manual smoke on all four paths (exit 2; ANSI stripped under `NO_COLOR=1 | cat`; preserved under `CLICOLOR_FORCE=1`) - [x] Aliases containing `subcommand` echoed verbatim under typo --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Closed
max-sixty
pushed a commit
that referenced
this pull request
Oct 1, 2026
) `wt <alias> --<Tab>` (and `wt step <alias> --<Tab>`) offered `--dry-run` and `--var`, but neither does anything useful after an alias. `AliasOptions::parse` rejects `--dry-run` with "`--dry-run` is no longer supported; use `wt config alias dry-run <name>` instead" (unless the template references `dry_run`), and passes `--var KEY=VALUE` through to the alias as plain positional arguments. Completion was steering users into an error or a flag that silently does nothing. The flags come from `build_alias_completion_command` in `src/completion.rs`, a stub that predates alias argument routing (added in #1641; `--dry-run` was retired for aliases in #2291 and #2304). This PR removes the stub's own `--dry-run`, `--yes` and `--var` declarations, so the stub declares nothing beyond the alias name and help text. Aliases that wrap a built-in (`co = "wt switch {{ args }}"`) still mirror that built-in's flags through `mirror_alias_command`, which this PR doesn't touch. **Test:** `test_complete_step_alias_shows_flags`, which asserted the stale flags were present, becomes `test_complete_step_alias_offers_no_misleading_flags` and asserts `--dry-run` and `--var` are absent. It fails on `main` (`Unexpected --dry-run flag`) and passes with the fix. All 80 completion integration tests pass. **Not covered:** `--yes` still completes after an alias, and so do `--config` and `--verbose`, because they are clap `global = true` flags on the root command and propagate into every subcommand's completions. After an alias they also forward as arguments (the alias parser tests note that `global = true` doesn't cross `external_subcommand`). Removing them would mean hiding globals per alias stub, which is a separate decision. The stub's own `--yes` declaration duplicated the global, so dropping it changes nothing. Co-authored-by: worktrunk-bot <[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.
Routes
--KEY=VALUEtokens based on what the template references. Tokens whoseKEYappears as{{ KEY }}in the alias bind to that variable; everything else joins{{ args }}. Space form--KEY VALUEis equivalent.Key changes:
referenced_vars_for_config) to decide binding at parse time.--yesretired — usewt -y <alias>(the global form) instead.--dry-runon an alias invocation is also retired;wt config alias show/dry-run <name>replaces it (landed separately in feat(config): add wt config alias show and dry-run subcommands #2291).--my-var=xbinds{{ my_var }}.--is a literal-forward escape — everything after it forwards to{{ args }}regardless of bindings.wt <alias> --help/-hprints a hint pointing atwt config alias show/dry-runrather than silently forwarding the flag into{{ args }}.wt <alias> -- --helpstill forwards.Advisory warnings (printed on stderr, don't affect execution):
--KEY VALUEwith---prefixed VALUE: almost always a typo where--KEY=VALUEwas meant.wt config alias show/dry-runon a name that shadows a top-level built-in (e.g.list): the alias is unreachable viawt <name>.wt config alias dry-runnow prints# bound:and# args:routing comments above the rendered command so users can see how each token was interpreted.Docs rewrite of the aliases section: concrete fly preview-env example, "Passing values" section (renamed from the opaque "How arguments are routed"), routing mechanism moved above the introspection tools,
uprebase recipe restored,since-mainalias added.Test plan
cargo test --lib --bins commands::alias::tests— unit tests (new: duplicate-key precedence, footgun warning, multi-=value)cargo test --test integration step_alias— integration tests (new: shadow warning onshowanddry-run,--helpintercept, retired--dry-runviawt step)cargo test --test integration test_command_pages_and_skill_files_are_in_sync— skill file synccargo run -- hook pre-merge --yes— full test suite + lints green🤖 Generated with Claude Code