Skip to content

Commit 9f9ee39

Browse files
committed
fix: use value_names for better help text in RunCommand
Use `value_names = ["TASK_SPECIFIER", "ADDITIONAL_ARGS"]` so the help output shows `[TASK_SPECIFIER] [ADDITIONAL_ARGS]...` instead of the generic `[TASK_AND_ARGS]...`. https://claude.ai/code/session_018viAL2UGVNfLuUjTsi44HQ
1 parent 62dbcab commit 9f9ee39

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

crates/vite_task/src/cli/mod.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,16 @@ impl RunFlags {
7474
///
7575
/// Contains the `--last-details` flag which is resolved into a separate
7676
/// `ResolvedCommand::RunLastDetails` variant internally.
77+
///
78+
/// `trailing_var_arg` at the command level makes clap stop matching flags once
79+
/// the trailing positional starts being filled. This means all tokens after the
80+
/// task name are passed through to the task verbatim, preventing flags like `-v`
81+
/// from being intercepted. Flags intended for `vp` itself (e.g. `--verbose`,
82+
/// `-r`) must appear **before** the task name.
83+
///
84+
/// See <https://github.com/voidzero-dev/vite-task/issues/285>.
7785
#[derive(Debug, clap::Parser)]
86+
#[command(trailing_var_arg = true)]
7887
pub struct RunCommand {
7988
#[clap(flatten)]
8089
pub(crate) flags: RunFlags,
@@ -83,11 +92,9 @@ pub struct RunCommand {
8392
#[clap(long, exclusive = true)]
8493
pub(crate) last_details: bool,
8594

86-
/// The task name and all arguments to pass to the task process
87-
/// Prevent flags after the task name to be consumed by Vite Task with `trailing_var_arg`
88-
///
89-
/// <https://github.com/voidzero-dev/vite-task/issues/285>
90-
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
95+
/// `packageName#taskName` or `taskName`, followed by any additional
96+
/// arguments to pass to the task.
97+
#[clap(allow_hyphen_values = true, value_names = ["TASK_SPECIFIER", "ADDITIONAL_ARGS"])]
9198
pub(crate) task_and_args: Vec<Str>,
9299
}
93100

@@ -160,14 +167,15 @@ pub struct ResolvedRunCommand {
160167

161168
impl RunCommand {
162169
/// Convert to the resolved run command, stripping the `last_details` flag.
170+
///
171+
/// Splits `task_and_args` into `task_specifier` (the first element) and
172+
/// `additional_args` (everything that follows).
163173
#[must_use]
164174
pub(crate) fn into_resolved(self) -> ResolvedRunCommand {
165175
let mut iter = self.task_and_args.into_iter();
166-
ResolvedRunCommand {
167-
task_specifier: iter.next(),
168-
flags: self.flags,
169-
additional_args: iter.collect(),
170-
}
176+
let task_specifier = iter.next();
177+
let additional_args: Vec<Str> = iter.collect();
178+
ResolvedRunCommand { task_specifier, flags: self.flags, additional_args }
171179
}
172180
}
173181

crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache and --no-cache conflict.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-overri
1111
---
1212
error: the argument '--cache' cannot be used with '--no-cache'
1313

14-
Usage: vt run --cache <TASK_AND_ARGS>...
14+
Usage: vt run --cache <TASK_SPECIFIER> <ADDITIONAL_ARGS>...
1515

1616
For more information, try '--help'.

0 commit comments

Comments
 (0)