Repository navigation
feat(config): add wt config alias show and dry-run subcommands - #2291
Conversation
Introduce `wt config alias show <name>` (print the configured template, source-labeled) and `wt config alias dry-run <name> [-- args...]` (render the expansion for a specific invocation). The new subcommands pull the preview / introspection surface off the alias dispatch path and give it a natural home next to the rest of `wt config`. Remove the `--dry-run` flag from `AliasOptions` — previously reachable as `wt <alias> --dry-run` and `wt step <alias> --dry-run`. Both paths now surface an actionable error pointing at the new subcommand (no deprecation period: top-level alias dispatch is recent and cutover is acceptable). Other changes: - Tab-completion completes alias names under `show` / `dry-run`. - `AliasSource` and a new `step_names_from_config` helper are promoted to shared utilities so `wt config alias`, the alias announcement, and the alias summary formatter read from one source. - `render_for_dry_run` is gone; its lazy-expansion logic lives in `handle_alias_dry_run::render_preview`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Resolves conflicts with main's two major landings since the branch diverged: - Global `-y`/`--yes` flag (PR #2279): `AliasOptions` no longer carries a `yes` field — approval skip comes from the top-level global. The post-alias `--yes` form now errors as an unknown flag, and post-alias `-y` falls into the positional-args branch. - Approvals module split (PR #2282): `add_approvals` / `clear_approvals` moved from `hook_commands` into `src/commands/config/approvals.rs`. The alias changes in this branch are compatible with both landings: - `AliasOptions` drops both `dry_run` and `yes`, keeping only `name`, `vars`, and `positional_args`. - `run_alias` uses `global_yes` from main's signature as the sole source for skipping approval. - `--dry-run` remains a parser-level error pointing at `wt config alias dry-run <name>`. - Existing `wt config alias dry-run` integration tests dropped the unused `-y` flag — dry-run never needs approval because it doesn't execute. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI failure on Linux is real and mechanical. The tests test_step_alias_dry_run and test_step_alias_dry_run_vars_across_steps were renamed to test_config_alias_dry_run{,_vars_across_steps} and their snapshots regenerated under the new names, but the old .snap files weren't removed. cargo insta test --unreferenced reject aborts on them.
error: aborting because of unreferenced snapshots
tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run.snap
tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run_vars_across_steps.snap
Fix:
git rm tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run.snap \
tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run_vars_across_steps.snapHappy to push this as a follow-up commit if you'd like.
CI failed — two unreferenced snapshot files from the rename need to be removed
- Drop two snapshots orphaned when the original `--dry-run` tests moved to `wt config alias dry-run` (insta --unreferenced reject caught these in CI). - Add `test_config_alias_show_user_and_project` to exercise the multi-entry display path — triggers the inter-entry separator that the single-source snapshot tests skip. - Add `test_config_alias_show_unknown_no_suggestions` to cover the empty- `did_you_mean` branch of `unknown_alias_error` — the existing unknown-name test uses a typo with a near match, always hitting the context-with- suggestions path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replace the two-line `name (source)` / `pipeline: ...` header with a
single info-style line and join all commands into one gutter block:
○ Alias deploy (project):
┃ # install
┃ npm install
┃ # build
┃ npm run build
`dry-run` keeps the same layout and only differs in the header verb
(`... would run:`), mirroring the pre-split `wt <alias> --dry-run`
output. Drops the redundant `(single command)` / `N unnamed steps`
fallback lines.
Co-Authored-By: Claude <[email protected]>
# Conflicts: # docs/content/extending.md # skills/worktrunk/reference/extending.md # src/commands/alias.rs # tests/integration_tests/step_alias.rs # tests/snapshots/integration__integration_tests__step_alias__step_alias_binds_space_separated_var.snap
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is red on the merge commit with a compile error in src/commands/config/alias.rs:94. PR #2299 (now on main) changed referenced_vars_for_config to return anyhow::Result<BTreeSet<String>>, and the new call site here calls it without ? — so .extend() is fed the Result instead of the inner BTreeSet. Same message across lint/test (linux/macos/windows)/coverage.
Happy to push the ? as a follow-up if that helps.
CI failing — compile error from main merge (referenced_vars_for_config signature change not propagated)
PR #2299 landed on main during my merge: `referenced_vars_for_config` now returns `anyhow::Result<BTreeSet<String>>` and surfaces template parse errors instead of silently skipping them. The dry-run call site in `handle_alias_dry_run` needs `?` to unwrap before extending. Co-Authored-By: Claude <[email protected]>
Routes `--KEY=VALUE` tokens based on what the template references.
Tokens whose `KEY` appears as `{{ KEY }}` in the alias bind to that
variable; everything else joins `{{ args }}`. Space form `--KEY VALUE`
is equivalent.
Key changes:
- Parser uses template reference introspection (via
`referenced_vars_for_config`) to decide binding at parse time.
- Post-alias `--yes` retired — use `wt -y <alias>` (the global form)
instead. `--dry-run` on an alias invocation is also retired; `wt config
alias show/dry-run <name>` replaces it (landed separately in #2291).
- Hyphens in keys canonicalize to underscores, so `--my-var=x` binds `{{
my_var }}`.
- `--` is a literal-forward escape — everything after it forwards to `{{
args }}` regardless of bindings.
- `wt <alias> --help` / `-h` prints a hint pointing at `wt config alias
show/dry-run` rather than silently forwarding the flag into `{{ args
}}`. `wt <alias> -- --help` still forwards.
Advisory warnings (printed on stderr, don't affect execution):
- `--KEY VALUE` with `--`-prefixed VALUE: almost always a typo where
`--KEY=VALUE` was meant.
- `wt config alias show`/`dry-run` on a name that shadows a top-level
built-in (e.g. `list`): the alias is unreachable via `wt <name>`.
`wt config alias dry-run` now 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, `up`
rebase recipe restored, `since-main` alias added.
## Test plan
- [x] `cargo test --lib --bins commands::alias::tests` — unit tests
(new: duplicate-key precedence, footgun warning, multi-`=` value)
- [x] `cargo test --test integration step_alias` — integration tests
(new: shadow warning on `show` and `dry-run`, `--help` intercept,
retired `--dry-run` via `wt step`)
- [x] `cargo test --test integration
test_command_pages_and_skill_files_are_in_sync` — skill file sync
- [x] `cargo run -- hook pre-merge --yes` — full test suite + lints
green
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Worktrunk Bot <[email protected]>
) `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]>
Summary
Third PR in the series simplifying alias-control flags. Introduces
wt config aliasas the home for alias introspection and removes the--dry-runflag that lived on alias dispatch.wt config alias show <name>— prints the configured template, source-labeled (user/project). Each step in a pipeline is rendered in a single gutter block with# <step-name>comment lines above named steps.wt config alias dry-run <name> [-- args...]— parses the arguments with the same parserwt <alias>uses, renders templates against the execution-time context, and prints without running. Args after--are forwarded verbatim, sowt config alias dry-run s -- target-branchpreviews exactly whatwt s target-branchwould run. Same layout asshow; only the header verb differs (:vswould run:).--dry-runremoved fromAliasOptions— bothwt <alias> --dry-runandwt step <alias> --dry-runnow return an actionable error pointing at the new subcommand. No deprecation period: top-level alias dispatch is recent, so cutover is acceptable.show/dry-run.Output format
The
○ Alias <name> (<source>)header matches the existinginfo_messagestyle. Bolding the name (what the user typed) and tagging the source in parens keeps the invocation identifier visually primary. When both user and project define the same alias, both entries print back-to-back (user first, matching runtime execution order).Design notes
AliasOptions::parseas the source of truth for invocation parsing, so preview stays aligned with runtime. When user and project configs both define the alias,referenced_varsis unioned across entries so a flag binds if any template references it.vars.*are shown unexpanded, mirroring the lazy execution path — those values are read from git config just before each step runs, potentially after earlier steps have set them. Syntax errors still surface up front.wt step <alias>also breaks since both paths shareAliasOptions::parse. That's fine —wt step <alias>has no forward-compat promise beyond the basic call.AliasSourceis promoted topub(crate)with alabel()helper sowt config aliasand the alias runtime code read from one enum.Navigating the diff
src/cli/config.rs— addsConfigAliasCommand+ theAliasvariant onConfigCommand.src/commands/config/alias.rs— new module.handle_alias_showandhandle_alias_dry_runshare aformat_entryhelper; theverb: Option<&str>parameter is the only difference between show and dry-run output.render_previewreplaces the oldrender_for_dry_runin alias dispatch.src/commands/alias.rs— the--dry-runflag and its rendering branch are gone. The parser bails on--dry-runwith a migration message pointing at the new subcommand; the bail sits after the--literal-mode check, sowt alias -- --dry-runstill forwards as positional.src/completion.rs—alias_name_completer()mirrors the existinghook_command_name_completerpattern.tests/integration_tests/step_alias.rs— existing--dry-runtests migrate towt config alias dry-run, plus new coverage forshow, unknown-alias suggestions, and the retired-flag error.docs/content/extending.md— adds an "Inspecting and previewing" subsection.Test plan
wt hook pre-merge --yes(3271 tests, all passing)cargo insta test --accept— all snapshots up to datecargo test --test integration test_command_pages_and_skill_files_are_in_sync— docs syncedwt config alias show <name>andwt config alias dry-run <name> [-- args...]in a repo with mixed user/project aliases