Forward help/version flags to tasks in run alias#53
Closed
kjanat wants to merge 1 commit into
Closed
Conversation
`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
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
🚫 Excluded labels (none allowed) (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
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.
Summary
The
runalias now intelligently forwards--help/-hand--version/-Vflags 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 therun <task> --workaround to pass help flags to tasks.Key Changes
Disabled clap's built-in help/version flags on
RunAliasClito prevent them from short-circuiting parsing. This allows the flags to be treated as undefined hyphen tokens that can be forwarded to tasks via thetrailing_var_argmechanism.Added builtin request classification via new
alias_builtin_request()function that detects when a parse error represents a help/version request (identified byUnknownArgumenterrors for these flags before any task).Added
print_run_alias_help()function to render the binary's own help when-h/--helpprecedes any task, usingargv[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:
--help/--version(before any task) cannot fill the hyphen-rejectingtaskpositional argument, so it surfaces as anUnknownArgumenterror that we recognize and handle.--help/--version(after a task) is captured byargswithtrailing_var_arg = trueandallow_hyphen_values = true, allowing it to be forwarded to the task.--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.