diff --git a/README.md b/README.md index 144eeab2..a3cee071 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Install [Vite+](https://viteplus.dev), then run tasks from your workspace. See t ```bash vp run build # run a task in the current package -vp run build -r # run across all packages in dependency order -vp run @my/app#build -t # run in a package and its transitive dependencies +vp run -r build # run across all packages in dependency order +vp run -t @my/app#build # run in a package and its transitive dependencies vp run --cache build # run with caching enabled ``` diff --git a/crates/vite_task/src/cli/mod.rs b/crates/vite_task/src/cli/mod.rs index 35b32a0c..dd4605e7 100644 --- a/crates/vite_task/src/cli/mod.rs +++ b/crates/vite_task/src/cli/mod.rs @@ -76,19 +76,19 @@ impl RunFlags { /// `ResolvedCommand::RunLastDetails` variant internally. #[derive(Debug, clap::Parser)] pub struct RunCommand { - /// `packageName#taskName` or `taskName`. If omitted, lists all available tasks. - pub(crate) task_specifier: Option, - #[clap(flatten)] pub(crate) flags: RunFlags, - /// Additional arguments to pass to the tasks - #[clap(trailing_var_arg = true, allow_hyphen_values = true)] - pub(crate) additional_args: Vec, - /// Display the detailed summary of the last run. #[clap(long, exclusive = true)] pub(crate) last_details: bool, + + /// The task name and all arguments to pass to the task process + /// Prevent flags after the task name to be consumed by Vite Task with `trailing_var_arg` + /// + /// + #[clap(trailing_var_arg = true, allow_hyphen_values = true)] + pub(crate) task_and_args: Vec, } /// vite task CLI subcommands as parsed by clap. @@ -162,10 +162,11 @@ impl RunCommand { /// Convert to the resolved run command, stripping the `last_details` flag. #[must_use] pub(crate) fn into_resolved(self) -> ResolvedRunCommand { + let mut iter = self.task_and_args.into_iter(); ResolvedRunCommand { - task_specifier: self.task_specifier, + task_specifier: iter.next(), flags: self.flags, - additional_args: self.additional_args, + additional_args: iter.collect(), } } } diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-non-zero-exit/snapshots/builtin command with non-zero exit does not show cache not updated.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-non-zero-exit/snapshots/builtin command with non-zero exit does not show cache not updated.snap index 81774f05..b74a8fc0 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-non-zero-exit/snapshots/builtin command with non-zero exit does not show cache not updated.snap +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-non-zero-exit/snapshots/builtin command with non-zero exit does not show cache not updated.snap @@ -3,7 +3,7 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs expression: e2e_outputs --- [1]> vt run lint -- -D no-debugger -$ vt lint -D no-debugger +$ vt lint -- -D no-debugger x eslint(no-debugger): `debugger` statement is not allowed ,-[bad.js:1:1] @@ -15,7 +15,7 @@ $ vt lint -D no-debugger Found 0 warnings and 1 error. Finished in on 1 file with 93 rules using threads. [1]> vt run lint -- -D no-debugger -$ vt lint -D no-debugger +$ vt lint -- -D no-debugger x eslint(no-debugger): `debugger` statement is not allowed ,-[bad.js:1:1] diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test prints value from additional_envs.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test prints value from additional_envs.snap index 953cca78..c2f767bb 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test prints value from additional_envs.snap +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test prints value from additional_envs.snap @@ -3,5 +3,5 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs expression: e2e_outputs --- > vt run env-test -- SYNTHETIC_ENV_VAR test_value_from_synthesizer # prints env value -$ vt env-test SYNTHETIC_ENV_VAR test_value_from_synthesizer +$ vt env-test -- SYNTHETIC_ENV_VAR test_value_from_synthesizer test_value_from_synthesizer diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test with different values.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test with different values.snap index 7b5c67fc..83de9cad 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test with different values.snap +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/e2e-env-test/snapshots/env-test with different values.snap @@ -3,8 +3,8 @@ source: crates/vite_task_bin/tests/e2e_snapshots/main.rs expression: e2e_outputs --- > vt run env-test -- FOO bar # sets FOO=bar -$ vt env-test FOO bar +$ vt env-test -- FOO bar bar > vt run env-test -- BAZ qux # sets BAZ=qux -$ vt env-test BAZ qux +$ vt env-test -- BAZ qux qux diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/package.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/package.json new file mode 100644 index 00000000..0e0f5335 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "echo": "echo" + } +} diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/snapshots.toml b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/snapshots.toml new file mode 100644 index 00000000..1f314994 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/snapshots.toml @@ -0,0 +1,11 @@ +# Tests that arguments after task name should be passed to the task +# https://github.com/voidzero-dev/vite-task/issues/285 + +[[e2e]] +name = "pass args to task" +steps = [ + "vt run echo --help", # Should just print `help` instead of Vite task's help + "vt run echo --version", # Should just print `version` instead of Vite task's version + "vt run echo -v", # Should just print `-v` + "vt run echo -a", # Should just print `-a` +] diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/snapshots/pass args to task.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/snapshots/pass args to task.snap new file mode 100644 index 00000000..b67cb323 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/snapshots/pass args to task.snap @@ -0,0 +1,16 @@ +--- +source: crates/vite_task_bin/tests/e2e_snapshots/main.rs +expression: e2e_outputs +--- +> vt run echo --help +$ echo --help ⊘ cache disabled +--help +> vt run echo --version +$ echo --version ⊘ cache disabled +--version +> vt run echo -v +$ echo -v ⊘ cache disabled +-v +> vt run echo -a +$ echo -a ⊘ cache disabled +-a diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/vite-task.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/vite-task.json new file mode 100644 index 00000000..b39113d0 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/pass-args-to-task/vite-task.json @@ -0,0 +1,3 @@ +{ + "cache": false +} diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml index 115ea39f..77d6d154 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots.toml @@ -214,7 +214,7 @@ steps = ["vt run --verbose"] name = "verbose with typo enters selector" cwd = "packages/app" steps = [ - { command = "vt run buid --verbose", interactions = [ + { command = "vt run --verbose buid", interactions = [ { "expect-milestone" = "task-select:buid:0" }, { "write-key" = "enter" }, ] }, diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots/verbose with typo enters selector.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots/verbose with typo enters selector.snap index dc2c457e..bc084185 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots/verbose with typo enters selector.snap +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/task-select/snapshots/verbose with typo enters selector.snap @@ -4,7 +4,7 @@ expression: e2e_outputs info: cwd: packages/app --- -> vt run buid --verbose +> vt run --verbose buid @ expect-milestone: task-select:buid:0 Task "buid" not found. Select a task (↑/↓, Enter to run, type to search): buid diff --git a/crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache and --no-cache conflict.snap b/crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache and --no-cache conflict.snap index ef47908e..f2467331 100644 --- a/crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache and --no-cache conflict.snap +++ b/crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache and --no-cache conflict.snap @@ -11,6 +11,6 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-overri --- error: the argument '--cache' cannot be used with '--no-cache' -Usage: vt run --cache [ADDITIONAL_ARGS]... +Usage: vt run --cache ... For more information, try '--help'.