Repository navigation
refactor(cli): drop post-alias --yes from hand-rolled parser - #2290
Merged
Merged
Conversation
PR #2279 promoted -y/--yes to a top-level global clap flag, but AliasOptions::parse kept consuming a post-alias --yes for back-compat. Remove that path so global_yes is the single source for skip_approval. Why a real cutover, not a no-op: clap's global = true does not propagate flags across an external_subcommand boundary (verified against clap 4.6), so wt deploy --yes was never reaching the global parser — it only worked because the hand-rolled parser consumed it. Removing the field is a user-visible removal of the post-alias form. Use wt -y deploy or wt --yes deploy (pre-alias) instead. The post-alias --yes now errors as an unknown flag; -y (single-dash) silently becomes a {{ args }} positional. Co-authored-by: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 18, 2026
4 tasks done
max-sixty
added a commit
that referenced
this pull request
Apr 18, 2026
… --var (#2287) ## Summary Replace the alias-arg parser's "every `--KEY=VALUE` binds; bare `--KEY` errors" 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=VALUE` special cases. The template already declares which variables it consumes — using that as the routing signal removes both surprise binding (silent `env=staging` for templates that never reference `env`) 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: | Token shape | Routes to | |---|---| | `--KEY=VALUE` or `--KEY VALUE` where the template references `{{ KEY }}` | Bound — `KEY` becomes the template value | | `--KEY=VALUE` where the template doesn't reference `KEY` | Forwarded literally to `{{ args }}` | | `--KEY` followed by another `--…` (or end of args) | Forwarded literally to `{{ args }}` | | Bare positional | Forwarded to `{{ args }}` | | Anything after `--` | Forwarded to `{{ args }}` regardless of shape | `--dry-run` is the only post-alias built-in. `--yes`/`-y` is global only (`wt -y <alias>`) per #2290 — post-alias `--yes` falls through the shape rule and forwards as positional. Hyphens in the key canonicalize to underscores before lookup, so `--my-var=value` binds to `{{ my_var }}`. ## Behavior changes | Input | Before | After | |---|---|---| | `wt rm --force` (no `{{ force }}` ref) | Errored "Unknown flag" | Forwards `--force` to `{{ args }}` | | `wt deploy --env staging` | Errored "Unknown flag" | Binds `env=staging` if referenced; else forwards both to `{{ args }}` | | `wt deploy --env=staging` (no `{{ env }}` ref) | Silently bound `env=staging` | Forwards `--env=staging` to `{{ args }}` | | `wt foo --var x=1` | Bound `x=1` via the special `--var` arm | Same as `--var=x=1`: binds `var="x=1"` if referenced, else forwards | | `wt run -- --env=staging` | `--env=staging` consumed | `--env=staging` forwarded literally | | `wt show --branch=override` (with `{{ branch }}` ref) | Bound (worked, undocumented) | Bound, now documented and tested | Users who relied on `--var KEY=VALUE` should switch to `--KEY=VALUE` directly. ## Navigating the diff - `src/commands/alias.rs` — `AliasOptions::parse` rewritten as a left-to-right walk against `referenced_vars: &BTreeSet<String>`. `try_alias` and `step_alias` resolve the alias's `CommandConfig` first, compute `referenced_vars`, then parse. `step_alias` now takes `Vec<String>` (parses internally) because routing needs the resolved alias. - `src/config/expansion.rs` — new `referenced_vars_for_config` helper unions `template.undeclared_variables(false)` across every command in a pipeline. - `src/main.rs` — call site updated for new `step_alias` signature. - `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 `--var` tests are gone. - `tests/integration_tests/approval_ui.rs` — updated `test_post_alias_yes_does_not_skip_approval` (renamed from main's `…_no_longer_supported`): under the new grammar `--yes` doesn'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 - [x] `cargo run -- hook pre-merge --yes` (3255 tests, all pass) - [x] Unit tests for parse grammar: `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`/`-y` forwarding), `test_referenced_vars_for_config_unions_steps` - [x] Integration tests for end-to-end routing - [x] Doc sync test passes > _This was written by Claude Code on behalf of Maximilian_ --------- Co-authored-by: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Apr 19, 2026
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]>
max-sixty
pushed a commit
that referenced
this pull request
Sep 9, 2026
…alue>` (#4058) An alias whose template references `{{ dry_run }}` can't be given `--dry-run <value>` in the space-separated form. `AliasOptions::parse` matches that exact token before any routing and bails with worktrunk's retired-flag migration error, whatever the template binds: ```console $ cat ~/.config/worktrunk/config.toml [aliases] deploy = "./deploy.sh {% if dry_run %}--dry-run{% endif %}" $ wt deploy --dry-run 1 ✗ --dry-run is no longer supported; use `wt config alias dry-run deploy` instead ``` The `=` spelling of the same flag already binds, because the bail compares the whole token and `--dry-run=1` isn't equal to `--dry-run`. So the two forms of one flag disagree, and the error names a subcommand that previews the alias rather than passing the value the user was trying to pass. ## Change The bail yields to a template that references `dry_run` — one condition, in the parser's existing routing loop — but only for the value-taking spellings. This is the deference the parser already gives the two comparable flags: `try_intercept_alias_help` intercepts `--help` "only when the template doesn't reference [`help`]", and `--yes` — retired from the post-alias position by [#2290](#2290) — follows the ordinary `--KEY` rule and binds when `yes` is referenced. A **bare `--dry-run` with nothing to consume still bails**, in both the referenced and unreferenced cases. The general `--KEY` end-of-args rule forwards such a token into `{{ args }}`, which for a `{% if dry_run %}` template means `dry_run` stays unset and the live command runs with exit 0 and nothing on stderr — the silent forward this bail exists to prevent, on the flag whose purpose is not doing the thing. Failing there is what [Data Safety](https://github.com/max-sixty/worktrunk/blob/de4558fa29ce2273e6b3ce297b1c5d6c5408a220/CLAUDE.md) asks for ("prefer failure over silent loss"), and it costs the user only the `=`: the referenced case gets its own message naming `--dry-run=1`, since `wt config alias dry-run <name>` previews the alias rather than passing a value. Everything else is untouched: an alias that doesn't reference `dry_run` still gets the migration error, and `wt deploy -- --dry-run` still forwards the token as a positional. ## Testing Against a build of this branch, with `deploy = "echo ./deploy.sh {% if dry_run %}--dry-run{% endif %}"`: ```console $ wt deploy --dry-run ✗ --dry-run at the end of the command binds nothing, leaving `dry_run` unset in deploy; pass `--dry-run=1` instead $ wt deploy --dry-run 1 ./deploy.sh --dry-run $ wt deploy --dry-run=1 ./deploy.sh --dry-run $ wt deploy ./deploy.sh ``` `test_parse_dry_run_binds_when_referenced` pins the two value-taking spellings (both fail on `main` — the first assertion panics unwrapping the bail). `test_parse_dry_run_bare_errors_when_referenced` pins the bare form's error and the `--` literal forward beside it. `test_parse_errors` keeps the unreferenced case on the migration error. `cargo test --bins alias` (33) and `cargo test --test integration step_alias` (81) pass; `cargo clippy --bin wt --all-targets` is clean. Found by the nightly survey reading `src/commands/alias.rs`; no user reported it. --------- 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.
PR #2279 promoted
-y/--yesto a top-level global clap flag. The hand-rolledAliasOptions::parsekept consuming a post-alias--yesfor back-compat — that's the deferred cleanup landing here.run_aliasnow reads only the global flag (skip_approval = global_yes).This is a real cutover, not a no-op. Clap's
global = truedoes not propagate flags across anexternal_subcommandboundary (verified against clap 4.6 —wt deploy --yesresults inCustom(["deploy", "--yes"])withglobal_yes = false). So the post-alias form was never reaching the global parser; it only worked becauseAliasOptions::parseconsumed it. Removing the field removes user-visible behavior:wt -y deploywt --yes deploywt deploy --yeswt deploy -y-yas{{ args }}positionalThe
--yes/-yasymmetry on the post-alias side is documented in theAliasOptions::parsedocstring and locked in by parser tests.Test changes
test_post_alias_yes_still_works→test_post_alias_yes_no_longer_supported(asserts the new error)tests/integration_tests/step_alias.rsmigrated from&[..., "--yes"]tomake_snapshot_cmd_with_global_flags(..., &["-y"])--yesflags removed fromtests/integration_tests/bare_repository.rs(theprint-repo-pathuser-config alias never required approval)