Skip to content

Commit dc2efc3

Browse files
committed
feat(cli): add top-level rebuild alias
1 parent 48e49ca commit dc2efc3

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

crates/vite_global_cli/src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::cli::{
3636

3737
/// Normalize CLI arguments:
3838
/// - `vp list ...` / `vp ls ...` → `vp pm list ...`
39+
/// - `vp rebuild ...` → `vp pm rebuild ...`
3940
/// - `vp help [command]` → `vp [command] --help`
4041
/// - `vp node [args...]` → `vp env exec node [args...]`
4142
fn normalize_args(args: Vec<String>) -> Vec<String> {
@@ -50,6 +51,15 @@ fn normalize_args(args: Vec<String>) -> Vec<String> {
5051
normalized.extend(args[2..].iter().cloned());
5152
normalized
5253
}
54+
// `vp rebuild ...` → `vp pm rebuild ...`
55+
Some("rebuild") => {
56+
let mut normalized = Vec::with_capacity(args.len() + 1);
57+
normalized.push(args[0].clone());
58+
normalized.push("pm".to_string());
59+
normalized.push("rebuild".to_string());
60+
normalized.extend(args[2..].iter().cloned());
61+
normalized
62+
}
5363
// `vp help` alone -> show main help
5464
Some("help") if args.len() == 2 => vec![args[0].clone(), "--help".to_string()],
5565
// `vp help [command] [args...]` -> `vp [command] --help [args...]`
@@ -434,6 +444,20 @@ mod tests {
434444
assert_eq!(normalized, s(&["vp", "env", "exec", "node"]));
435445
}
436446

447+
#[test]
448+
fn normalize_args_rewrites_bare_vp_rebuild() {
449+
let input = s(&["vp", "rebuild"]);
450+
let normalized = normalize_args(input);
451+
assert_eq!(normalized, s(&["vp", "pm", "rebuild"]));
452+
}
453+
454+
#[test]
455+
fn normalize_args_rewrites_vp_rebuild_with_args() {
456+
let input = s(&["vp", "rebuild", "--", "--update-binary"]);
457+
let normalized = normalize_args(input);
458+
assert_eq!(normalized, s(&["vp", "pm", "rebuild", "--", "--update-binary"]));
459+
}
460+
437461
#[test]
438462
fn unknown_argument_detected_without_pass_as_value_hint() {
439463
let error = try_parse_args_from(["vp".to_string(), "--cache".to_string()])

0 commit comments

Comments
 (0)