Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions packages/cli/binding/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,23 @@ impl CommandHandler for VitePlusCommandHandler {
}
// Parse "vp <args>" using CLIArgs — always use "vp" as the program name
// so clap shows "Usage: vp ..." even if the original command was "vite ..."
let cli_args =
CLIArgs::try_parse_from(iter::once("vp").chain(command.args.iter().map(Str::as_str)))?;
let cli_args = match CLIArgs::try_parse_from(
iter::once("vp").chain(command.args.iter().map(Str::as_str)),
) {
Ok(args) => args,
Err(err) if err.kind() == ErrorKind::InvalidSubcommand => {
return Ok(HandledCommand::Synthesized(
command.to_synthetic_plan_request(UserCacheConfig::disabled()),
Comment thread
fengmk2 marked this conversation as resolved.
));
}
Err(err) => return Err(err.into()),
};
match cli_args {
CLIArgs::Synthesizable(SynthesizableSubcommand::Check { .. }) => {
// Check is a composite command — run as a subprocess in task scripts
Ok(HandledCommand::Verbatim)
Ok(HandledCommand::Synthesized(
command.to_synthetic_plan_request(UserCacheConfig::disabled()),
))
}
CLIArgs::Synthesizable(subcmd) => {
let resolved = self.resolver.resolve(subcmd, &command.envs, &command.cwd).await?;
Expand All @@ -685,7 +696,9 @@ impl CommandHandler for VitePlusCommandHandler {
CLIArgs::ViteTask(cmd) => Ok(HandledCommand::ViteTaskCommand(cmd)),
CLIArgs::Exec(_) => {
// exec in task scripts should run as a subprocess
Ok(HandledCommand::Verbatim)
Ok(HandledCommand::Synthesized(
command.to_synthetic_plan_request(UserCacheConfig::disabled()),
))
}
}
}
Expand Down Expand Up @@ -1660,4 +1673,20 @@ mod tests {
let subcommand = SynthesizableSubcommand::Lint { args: vec!["src/index.ts".to_string()] };
assert!(!should_suppress_subcommand_stdout(&subcommand));
}

#[test]
fn global_subcommands_produce_invalid_subcommand_error() {
use clap::error::ErrorKind;

for subcommand in ["config", "create", "env", "migrate"] {
let error = CLIArgs::try_parse_from(["vp", subcommand])
.expect_err(&format!("expected error for global subcommand '{subcommand}'"));
assert_eq!(
error.kind(),
ErrorKind::InvalidSubcommand,
"expected InvalidSubcommand for '{subcommand}', got {:?}",
error.kind()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "command-run-with-vp-config",
"version": "1.0.0",
"scripts": {
"foo": "vp config",
"bar": "vp not-exist-command"
},
"packageManager": "pnpm@10.19.0"
}
26 changes: 26 additions & 0 deletions packages/cli/snap-tests/command-run-with-vp-config/snap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
> vp run foo # should run vp config command
$ vp config ⊘ cache disabled
.git can't be found

Created AGENTS.md with Vite+ instructions
◇ Add this MCP server config to your agent ─╮

{
"vite-plus": {
"command": "npx",
"args": [
"vp",
"mcp"
]
}
}

╰────────────────────────────────────────────╯


[2]> vp run bar # should throw error
$ vp not-exist-command ⊘ cache disabled
error: Command 'not-exist-command' not found

Did you mean `vp test`?

3 changes: 3 additions & 0 deletions packages/cli/snap-tests/command-run-with-vp-config/steps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"commands": ["vp run foo # should run vp config command", "vp run bar # should throw error"]
}
Loading