Skip to content

Commit 9bd2a4e

Browse files
Boshenclaudefengmk2
authored
chore(global_cli): clarify --help for vp env default/pin/use/exec (#1664)
## Summary Closes #949. Adds `Examples:` blocks (via clap `after_help`) to the four `vp env` subcommands flagged in the issue, so the intended invocation modes are visible directly from `--help`: - `vp env default` — show vs. set (with/without `<version>`) - `vp env pin` — show / pin / range / `--unpin` - `vp env use` — default / override `<version>` / `--unset` - `vp env exec` — explicit `--node <version>` vs. shim mode Also tightens per-argument doc comments ("If not provided" → "If omitted", missing period). No behavior changes. The clap auto-generated `Usage:` line is unchanged. The `command-env-use` snap was regenerated to capture the new `--help` output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: MK <fengmk2@gmail.com>
1 parent ada9d33 commit 9bd2a4e

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

  • crates/vite_global_cli/src
  • packages/cli/snap-tests-global/command-env-use

crates/vite_global_cli/src/cli.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,13 @@ pub enum EnvSubcommands {
298298
Print,
299299

300300
/// Set or show the global default Node.js version
301+
#[command(after_long_help = "\
302+
Examples:
303+
vp env default # Show the current default
304+
vp env default lts # Set the default")]
301305
Default {
302-
/// Version to set as default (e.g., "20.18.0", "lts", "latest")
303-
/// If not provided, shows the current default
306+
/// Version to set as default (e.g., "20.18.0", "lts", "latest").
307+
/// If omitted, prints the current default.
304308
version: Option<String>,
305309
},
306310

@@ -330,9 +334,14 @@ pub enum EnvSubcommands {
330334
},
331335

332336
/// Pin a Node.js version in the current directory (creates .node-version)
337+
#[command(after_long_help = "\
338+
Examples:
339+
vp env pin lts # Pin to latest LTS
340+
vp env pin --unpin # Remove .node-version
341+
vp env pin \"^20.0.0\" --force # Overwrite existing pin")]
333342
Pin {
334-
/// Version to pin (e.g., "20.18.0", "lts", "latest", "^20.0.0")
335-
/// If not provided, shows the current pinned version
343+
/// Version to pin (e.g., "20.18.0", "lts", "latest", "^20.0.0").
344+
/// If omitted, prints the currently pinned version.
336345
version: Option<String>,
337346

338347
/// Remove the .node-version file from current directory
@@ -383,11 +392,17 @@ pub enum EnvSubcommands {
383392
},
384393

385394
/// Execute a command with a specific Node.js version
386-
#[command(visible_alias = "run")]
395+
#[command(
396+
visible_alias = "run",
397+
after_long_help = "\
398+
Examples:
399+
vp env exec --node lts npm install # Pin version for this invocation
400+
vp env exec node -v # Shim mode: version auto-resolved"
401+
)]
387402
Exec {
388-
/// Node.js version to use (e.g., "20.18.0", "lts", "^20.0.0")
389-
/// If not provided and command is node/npm/npx or a global package binary,
390-
/// version is resolved automatically (same as shim behavior)
403+
/// Node.js version to use (e.g., "20.18.0", "lts", "^20.0.0").
404+
/// If omitted and command is node/npm/npx or a global package binary,
405+
/// version is resolved automatically (same as shim behavior).
391406
#[arg(long)]
392407
node: Option<String>,
393408

@@ -417,9 +432,13 @@ pub enum EnvSubcommands {
417432
},
418433

419434
/// Use a specific Node.js version for this shell session
435+
#[command(after_long_help = "\
436+
Examples:
437+
vp env use lts # Override session with latest LTS
438+
vp env use --unset # Clear the session override")]
420439
Use {
421-
/// Version to use (e.g., "20", "20.18.0", "lts", "latest")
422-
/// If not provided, reads from .node-version or package.json
440+
/// Version to use (e.g., "20", "20.18.0", "lts", "latest").
441+
/// If omitted, reads from .node-version or package.json.
423442
version: Option<String>,
424443

425444
/// Remove session override (revert to file-based resolution)

packages/cli/snap-tests-global/command-env-use/snap.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ Usage: vp env use [OPTIONS] [VERSION]
44
Use a specific Node.js version for this shell session
55

66
Arguments:
7-
[VERSION] Version to use (e.g., "20", "20.18.0", "lts", "latest") If not provided, reads from .node-version or package.json
7+
[VERSION] Version to use (e.g., "20", "20.18.0", "lts", "latest"). If omitted, reads from .node-version or package.json
88

99
Options:
1010
--unset Remove session override (revert to file-based resolution)
1111
--no-install Skip auto-installation if version not present
1212
--silent-if-unchanged Suppress output if version is already active
13-
-h, --help Print help
13+
-h, --help Print help (see a summary with '-h')
14+
15+
Examples:
16+
vp env use lts # Override session with latest LTS
17+
vp env use --unset # Clear the session override
1418

1519
Documentation: https://viteplus.dev/guide/env
1620

0 commit comments

Comments
 (0)