Skip to content

Forward help/version flags to tasks in run alias#53

Closed
kjanat wants to merge 1 commit into
masterfrom
claude/sleepy-bohr-f6tx38
Closed

Forward help/version flags to tasks in run alias#53
kjanat wants to merge 1 commit into
masterfrom
claude/sleepy-bohr-f6tx38

Conversation

@kjanat

@kjanat kjanat commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary

The run alias now intelligently forwards --help/-h and --version/-V flags to tasks when they follow a task name, while still printing the binary's own help/version when these flags appear before any task. This eliminates the need for the run <task> -- workaround to pass help flags to tasks.

Key Changes

  • Disabled clap's built-in help/version flags on RunAliasCli to prevent them from short-circuiting parsing. This allows the flags to be treated as undefined hyphen tokens that can be forwarded to tasks via the trailing_var_arg mechanism.

  • Added builtin request classification via new alias_builtin_request() function that detects when a parse error represents a help/version request (identified by UnknownArgument errors for these flags before any task).

  • Added print_run_alias_help() function to render the binary's own help when -h/--help precedes any task, using argv[0] for the bin name to match previous behavior.

  • Updated error handling in run_alias_in_dir() to intercept parse errors and classify them as builtin requests, routing them to appropriate handlers (help/version output) instead of rendering clap errors.

  • Updated help text to document the new forwarding behavior and clarify when flags are interpreted as the binary's own vs. forwarded to tasks.

Implementation Details

The solution leverages clap's argument parsing mechanics:

  • A leading --help/--version (before any task) cannot fill the hyphen-rejecting task positional argument, so it surfaces as an UnknownArgument error that we recognize and handle.
  • A trailing --help/--version (after a task) is captured by args with trailing_var_arg = true and allow_hyphen_values = true, allowing it to be forwarded to the task.
  • The -- separator continues to work for forcing literal forwarding of these flags.

Comprehensive test coverage added for all scenarios: forwarding after tasks, interleaved flags, double-dash handling, and leading builtin detection.

`run <task> --help` (and -h/-V/--version) now reach the task's own
help/version instead of printing the `run` alias's, removing the need
for `run <task> -- --help`. Bare `run --help`/`--version`, including
after global flags (`run --pm npm --help`), still print the alias's own
help/version, and `run <task> -- --help` still forwards literally.

clap's built-in help/version flags short-circuit parsing wherever they
appear, so they are disabled on RunAliasCli and left undefined. An
undefined hyphen token after the first positional is swallowed by `args`
(trailing_var_arg) and forwarded; a leading one can't fill the
hyphen-rejecting `task` positional and surfaces as UnknownArgument, which
run_alias_in_dir classifies as the alias's own help/version request. Since
-h/--help/-V/--version are no longer clap args, they are documented in the
help footer (after_help) rather than the options list.

The `runner run` subcommand is intentionally unchanged.

https://claude.ai/code/session_01W7rr83QsJjWjMBBeycjgrZ
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • cr:review
🚫 Excluded labels (none allowed) (2)
  • wip
  • cr:skip

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d89f3135-beca-4ada-9384-60d62302f117

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

@kjanat kjanat closed this Jun 14, 2026
@kjanat kjanat deleted the claude/sleepy-bohr-f6tx38 branch June 14, 2026 09:49
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.

1 participant