Repository navigation
feat(alias): route --key=value via template refs, add -- escape, drop --var - #2287
Conversation
… --var
Replace the old "every --KEY=VALUE binds; bare --KEY errors" grammar with
template-driven routing: a token only binds if the alias's pipeline
references {{ KEY }}. Otherwise it forwards into {{ args }}. Adds `--`
as a literal-forward escape and removes the `--var KEY=VALUE` /
`--var=KEY=VALUE` special cases — `--KEY=VALUE` covers the same use
case directly.
Co-Authored-By: Claude <[email protected]>
# Conflicts: # src/commands/alias.rs # src/main.rs
worktrunk-bot
left a comment
There was a problem hiding this comment.
Nicely done — template-driven routing is a much cleaner contract than the old shorthand, and the test coverage (referenced vs unreferenced, space-separated, -- escape, multi-step union, hyphen canonicalization) maps one-to-one with the grammar in the docstring.
One observation (not blocking — this is your call): CLAUDE.md states "Prefer deprecation warnings over silent breaks" for CLI flags. wt foo --var key=value no longer errors on upgrade; it forwards ["--var", "key=value"] into {{ args }} (or silently drops them if the template doesn't reference {{ args }}). A one-cycle deprecation — detecting --var as the leading token post-alias and printing a migration hint — would cushion the break without adding real complexity. Mentioning only because the PR description documents the migration path but the binary itself gives users no signal at the moment they hit the change. If you've already weighed this against the churn of keeping the special case around, disregard.
Minor unrelated: src/cli/hook.rs:41 still cross-references AliasOptions::parse as "alias variable shorthand" — the shorthand form is gone, so the analogy no longer holds. Outside this diff; happy to push a follow-up doc fix.
|
Linux CI is failing on Fix is a straight |
The two `--var`-form alias tests were deleted in this branch when the parser stopped special-casing `--var KEY=VALUE`, but their snapshot files were left behind. Pre-merge runs `cargo insta test --unreferenced reject`, which trips on orphans. Co-Authored-By: Claude <[email protected]>
# Conflicts: # src/commands/alias.rs # src/config/expansion.rs # src/config/mod.rs # tests/integration_tests/step_alias.rs
…nfig (#2299) Drops the silent `if let Ok(tmpl) = ...` skip in `referenced_vars_for_config` so a syntax error in any alias step surfaces before flags are routed. Previously, a malformed template made that step contribute no names to the referenced-var set, which silently changed how `--KEY=VALUE` tokens bound vs. forwarded as positionals — the deferred expansion path would only surface the syntax error later, after args may have been routed wrong. The helper now returns `anyhow::Result<BTreeSet<String>>`; callers in `try_alias` and `step_alias` propagate with `?`. New unit test covers the error path. Follow-up from review of #2287. > _This was written by Claude Code on behalf of Maximilian_ Co-authored-by: Claude <[email protected]>
Summary
Replace the alias-arg parser's "every
--KEY=VALUEbinds; bare--KEYerrors" grammar with template-driven routing. A token only binds when the alias's pipeline references{{ KEY }}; otherwise it forwards into{{ args }}. Adds--as a literal-forward escape and removes the--var KEY=VALUE/--var=KEY=VALUEspecial cases.The template already declares which variables it consumes — using that as the routing signal removes both surprise binding (silent
env=stagingfor templates that never referenceenv) and the unknown-flag error class. Every post-alias token now has a deterministic destination.Grammar
Tokens after
wt <alias>are walked left-to-right:--KEY=VALUEor--KEY VALUEwhere the template references{{ KEY }}KEYbecomes the template value--KEY=VALUEwhere the template doesn't referenceKEY{{ args }}--KEYfollowed by another--…(or end of args){{ args }}{{ args }}--{{ args }}regardless of shape--dry-runis the only post-alias built-in.--yes/-yis global only (wt -y <alias>) per #2290 — post-alias--yesfalls through the shape rule and forwards as positional. Hyphens in the key canonicalize to underscores before lookup, so--my-var=valuebinds to{{ my_var }}.Behavior changes
wt rm --force(no{{ force }}ref)--forceto{{ args }}wt deploy --env stagingenv=stagingif referenced; else forwards both to{{ args }}wt deploy --env=staging(no{{ env }}ref)env=staging--env=stagingto{{ args }}wt foo --var x=1x=1via the special--vararm--var=x=1: bindsvar="x=1"if referenced, else forwardswt run -- --env=staging--env=stagingconsumed--env=stagingforwarded literallywt show --branch=override(with{{ branch }}ref)Users who relied on
--var KEY=VALUEshould switch to--KEY=VALUEdirectly.Navigating the diff
src/commands/alias.rs—AliasOptions::parserewritten as a left-to-right walk againstreferenced_vars: &BTreeSet<String>.try_aliasandstep_aliasresolve the alias'sCommandConfigfirst, computereferenced_vars, then parse.step_aliasnow takesVec<String>(parses internally) because routing needs the resolved alias.src/config/expansion.rs— newreferenced_vars_for_confighelper unionstemplate.undeclared_variables(false)across every command in a pipeline.src/main.rs— call site updated for newstep_aliassignature.tests/integration_tests/step_alias.rs— six new integration tests cover the grammar end-to-end (referenced bind, unreferenced forward,--escape, multi-step binding, built-in overshadow, space-separated bind). The--vartests are gone.tests/integration_tests/approval_ui.rs— updatedtest_post_alias_yes_does_not_skip_approval(renamed from main's…_no_longer_supported): under the new grammar--yesdoesn't error, it forwards as positional, but still doesn't skip approval.docs/content/extending.md(and auto-synced skill reference) — new "How arguments are routed" section,--escape documented, built-in overshadow caveat added.Test plan
cargo run -- hook pre-merge --yes(3255 tests, all pass)test_parse_built_in_flags,test_parse_key_value_routing,test_parse_space_separated_routing,test_parse_hyphen_canonicalization,test_parse_literal_forward_escape,test_parse_mixed_pipeline,test_parse_positionals(covers post-alias--yes/-yforwarding),test_referenced_vars_for_config_unions_steps