Skip to content

fix(alias): forward help flags through aliases that accept arguments - #4856

Merged
max-sixty merged 3 commits into
max-sixty:mainfrom
sdi2200262:fix/issue-2305
Nov 21, 2026
Merged

max-sixty merged 3 commits into
max-sixty:mainfrom
sdi2200262:fix/issue-2305

Conversation

@sdi2200262

Copy link
Copy Markdown
Contributor

With sw = "wt switch {{ args }}", wt sw --help now prints the same help as wt switch --help. The short -h spelling passes through too. Both wt sw and wt step sw use the same rule.

Aliases that bind help keep their existing argument parsing. For a fixed alias, --help and -h show how to inspect it without running its body.

I checked both routes with the branch-built CLI, compared short and long help with direct wt switch output, and verified that requesting help for a fixed alias left its sentinel file absent. All 94 alias integration tests and the full pre-merge gate passed.

Another option is to let ordinary argument handling decide every invocation, including fixed aliases. I’m happy to replace this PR if you prefer that behavior.

Closes #2305.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For any alias whose template references args, wt <alias> --help now runs the whole alias. Nothing upstream catches the flag: try_intercept_alias_help was the only --help/-h check on the alias path, and run_alias gets everything it lets through. That's what you want for a wrapper like sw = "wt switch {{ args }}". Two common shapes don't behave as a help request:

  • Pipelines. args is collected across every step, so in release = ["cargo publish", "gh release create {{ args }}"] the help request runs cargo publish for real before gh ever sees --help.
  • Commands that don't read --help as help. With deploy = "./scripts/deploy.sh {{ args }}" or "echo building && make {{ args }}", the alias does its normal work and passes --help along as an ordinary argument.

Under the current intercept a user can type --help to find out what an alias does without running it. AliasOptions::parse protects --dry-run for the same reason: it is "the one flag whose purpose is not doing the thing". This change makes that protection depend on whether the template mentions args, and the user typing the command usually can't see the template. #2305 asks for feedback on exactly this, so it's a maintainer decision. One narrower rule would forward help only when the alias is a single command whose first word is wt (the sw case in the PR body) and keep the hint everywhere else.

The new docs row ends with "including binding --help=value to help". Few readers will ever write an alias that binds a help variable, and the general variable-binding docs already cover how --KEY=VALUE works. Consider cutting that clause.

@sdi2200262

Copy link
Copy Markdown
Contributor Author

I reproduced this with probe = ["touch ran-first", "printf '%s' {{ args }}"]. Running wt probe --help created ran-first, then printed --help. I documented that ordering and kept the current routing. Would you prefer multi-step aliases to show the inspection hint even when a step forwards arguments?

@sdi2200262
sdi2200262 marked this pull request as ready for review November 20, 2026 09:42
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

No, I'd keep the current routing. It matches what max-sixty leaned toward on #2305: forward --help through the alias, and keep the hint for aliases with no args, where forwarding would produce a confusing error. Adding a multi-step exception on top of that is the extra special-casing that comment warned about. It would also make wt <alias> --help behave differently depending on how many steps an alias has, which users can't see either. The new docs sentence covers the pipeline ordering, so I'm withdrawing that concern. It's still max-sixty's call on #2305.

One small thing is still open from my review: the docs row (and its copy in src/cli/hook.rs) still ends with "including binding --help=value to help". The general variable-binding docs already explain --KEY=VALUE, so I'd cut that clause.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment on test_alias_help_flag_after_double_dash_forwards in tests/integration_tests/step_alias.rs now says the wrong thing. It calls wt <alias> -- --help "the documented escape" that "bypasses the intercept". After this change, deploy = "echo {{ args }}" never hits the intercept, and the hint no longer mentions -- --help. The new test's probe -- --help case already covers that path. Either update the comment to say what the test checks now (literal -- still forwards), or drop the test as redundant.

I can push that fix together with the --help=value clause cut from my earlier comment, regenerating the doc mirrors at the same time. Just say so.

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

test (macos) failed on test_approval_prompt_accept, a PTY approval-prompt test this PR doesn't touch. It's a timing race in the test's input handling, tracked in #4859. A rerun of that job should clear it.

@sdi2200262

Copy link
Copy Markdown
Contributor Author

Okay, @worktrunk-bot, could you rerun the failed macOS job once?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Reran the failed test (macos) job once and it passed at 58f8786. No checks on the PR are failing or pending now.

@sdi2200262

Copy link
Copy Markdown
Contributor Author

@worktrunk-bot Thank you Mr. bot!

@max-sixty
max-sixty merged commit 1c1b49d into max-sixty:main Nov 21, 2026
45 of 46 checks passed
@max-sixty max-sixty mentioned this pull request Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feedback wanted: how should wt <alias> --help behave?

3 participants