Skip to content

Commit a2876b6

Browse files
liangmiQwQclaude
andauthored
feat(cli): error on vp install -g without package names (#1472)
Currently, running `vp install -g` with no package names will silently fall through to a regular workspace install, ignoring `--global` entirely, as the `global` check logic will only happen after checking package name is provided. This PR adjusted clap config to make sure package is provided when using `--global` flag, also adjusted help output for more clear guidance. Global snap test is also added to cover this case. Generated with [Claude Code](https://claude.com/claude-code) and Codex --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dbbd739 commit a2876b6

5 files changed

Lines changed: 17 additions & 3 deletions

File tree

crates/vite_global_cli/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ pub enum Commands {
145145
#[arg(long)]
146146
save_catalog: bool,
147147

148-
/// Install globally (only when adding packages)
149-
#[arg(short = 'g', long)]
148+
/// Install globally (requires package names)
149+
#[arg(short = 'g', long, requires = "packages")]
150150
global: bool,
151151

152152
/// Node.js version to use for global installation (only with -g)

packages/cli/snap-tests-global/cli-helper-message/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Options:
103103
--save-peer Save to peerDependencies (only when adding packages)
104104
-O, --save-optional Save to optionalDependencies (only when adding packages)
105105
--save-catalog Save the new dependency to the default catalog (only when adding packages)
106-
-g, --global Install globally (only when adding packages)
106+
-g, --global Install globally (requires package names)
107107
--node <NODE> Node.js version to use for global installation (only with -g)
108108
-h, --help Print help
109109

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "command-install-g-no-args"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[2]> vp install -g # Should error when no packages provided
2+
error: the following required arguments were not provided:
3+
<PACKAGES>...
4+
5+
Usage: vp install --global <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]
6+
7+
For more information, try '--help'.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"env": {},
3+
"commands": ["vp install -g # Should error when no packages provided"]
4+
}

0 commit comments

Comments
 (0)