Skip to content

refactor(cli): extract global-only commands into vp_global_only_cli - #2525

Closed
jong-kyung wants to merge 6 commits into
voidzero-dev:mainfrom
jong-kyung:refactor/extract-global-only-commands
Closed

refactor(cli): extract global-only commands into vp_global_only_cli#2525
jong-kyung wants to merge 6 commits into
voidzero-dev:mainfrom
jong-kyung:refactor/extract-global-only-commands

Conversation

@jong-kyung

@jong-kyung jong-kyung commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Extract the env, upgrade, and implode clap definitions out of crates/vp_global_cli/src/cli.rs into a new shared vp_global_only_cli crate as GlobalOnlyCommand, and flatten it back into the global Commands enum. This mirrors how vp_pm_cli::PackageManagerCommand is already shared between the global CLI and the local CLI binding.

The crate also exposes is_global_only(name), derived from the enum through clap's augment_subcommands, so the names can be recognised elsewhere without a hand-maintained list that can drift from the global surface. This addresses the review discussion in #2522, where the local binding needed the same list for its "only available in the global vp CLI" hint. Wiring that call into the local binding is left to #2522 itself.

The global CLI re-exports the moved types, so commands/env/* is unchanged. There is no behavior change: the global PTY snapshot suite passes without any snapshot updates, and cargo test -p vp_global_cli passes.

The RFCs that describe the shared CLI layout (merge-global-and-local-cli.md, global-cli-rust-binary.md) are updated to record the new crate.

Refs #2522

@netlify

netlify Bot commented Aug 21, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit b17aa69
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a885f1b35882b0008cf54df

@jong-kyung jong-kyung self-assigned this Aug 21, 2026
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: cd7cf7eb23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jong-kyung
jong-kyung force-pushed the refactor/extract-global-only-commands branch from e505ce3 to 1962a97 Compare August 21, 2026 13:49
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1962a97991

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_global_commands/src/lib.rs Outdated
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 9b536a847f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Move the env, upgrade, and implode clap definitions out of
crates/vp_global_cli/src/cli.rs into a shared crate as GlobalOnlyCommand,
and flatten it back into the global Commands enum. The crate also exposes
is_global_only(name), derived from the enum through clap, so the names can
be recognised elsewhere without a hand-maintained list that can drift from
the global surface.

The global CLI re-exports the moved types, so commands/env/* is unchanged.
No behavior change; global PTY snapshots pass without updates.
@jong-kyung
jong-kyung force-pushed the refactor/extract-global-only-commands branch from 9b536a8 to e440f0d Compare August 21, 2026 14:01
@jong-kyung jong-kyung changed the title refactor(cli): extract global-only commands into vp_global_commands refactor(cli): extract global-only commands into vp_global_only_cli Aug 21, 2026
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@jong-kyung

jong-kyung commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

if #2524 is merged, I'll add vp_global_only_cli to Rust create structure on AGENTS.md

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e440f0d6dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rfcs/merge-global-and-local-cli.md
@jong-kyung
jong-kyung force-pushed the refactor/extract-global-only-commands branch from 7b44924 to dd64873 Compare August 21, 2026 14:13
Document the shared global-only command crate next to the existing
vp_pm_cli notes in merge-global-and-local-cli.md, align the command
category letters with cli.rs, and update the file map in
global-cli-rust-binary.md.
@jong-kyung
jong-kyung force-pushed the refactor/extract-global-only-commands branch from dd64873 to c917708 Compare August 21, 2026 14:17
The redrawn four-category diagram is out of scope for this PR; keep the
original two-path diagram and leave the category text as the source of
truth.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

Replace the two-path ASCII diagram with a mermaid flowchart that shows all
four routing categories, matching the list below it.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 8ccd991d1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jong-kyung
jong-kyung marked this pull request as ready for review August 21, 2026 14:23
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b17aa69ead

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- **Category A (Package Manager)**: `install`, `add`, `remove`, `update`, `dedupe`, `outdated`, `why`, `info`, `link`, `unlink`, `dlx`, `pm <subcmd>` — clap definitions and dispatch live in the shared `crates/vp_pm_cli/` crate. Both the global CLI and the local CLI binding flatten `vp_pm_cli::PackageManagerCommand` into their top-level argument parser and call `vp_pm_cli::dispatch` to run the underlying package manager (pnpm/npm/yarn/bun). The global CLI additionally intercepts `--global` for vite-plus-managed installs (`commands::env::global_install`) before delegating.
- **Category B (JavaScript)**: All other commands (`build`, `test`, `lint`, `create`, `migrate`, `--version`, etc.) — Rust uses `oxc_resolver` to find the project's local `vite-plus/dist/bin.js` and runs it. Falls back to the global installation's `dist/bin.js` if no local installation exists. The unified `bin.ts` entry point then routes to either NAPI bindings (task commands and PM commands, the latter via `vp_pm_cli::dispatch`) or rolldown-bundled modules in `dist/global/` (create, migrate, version).
- **Category B (JavaScript)**: `create`, `migrate`, `config`, `hooks`, `staged`, `--version` — Rust uses `oxc_resolver` to find the project's local `vite-plus/dist/bin.js` and runs it. Falls back to the global installation's `dist/bin.js` if no local installation exists. The unified `bin.ts` entry point then routes to either NAPI bindings (task commands and PM commands, the latter via `vp_pm_cli::dispatch`) or rolldown-bundled modules in `dist/global/` (create, migrate, version).
- **Category C (Local CLI Delegation)**: `dev`, `build`, `test`, `lint`, `fmt`, `check`, `pack`, `run`, `exec`, `preview`, `cache` — forwarded to the project-local `vite-plus` CLI through `commands::delegate`, which resolves it the same way as Category B. `lint --init` and `fmt --init`/`--migrate` are forced to the global installation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Account for toolchain in the four-way routing model

The supposedly exhaustive four-category model leaves toolchain unclassified: this list ends with cache, but Commands::Toolchain remains a distinct top-level variant in crates/vp_global_cli/src/cli.rs (lines 207-220) and is dispatched through commands::toolchain::execute (lines 826-828), which either delegates locally or renders the global manifest depending on --global. Add this hybrid path to the diagram/category text or describe it as a separate category so readers do not infer that every command follows one of the four documented routes.

AGENTS.md reference: AGENTS.md:L63-L63

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but this gap predates this PR. I'll address it in a follow-up RFC update after this is merged.

cc. @fengmk2

@fengmk2

fengmk2 commented Aug 21, 2026

Copy link
Copy Markdown
Member

This implementation is a bit over-engineered. The independently separated vp_global_only_cli crate is somewhat redundant. Let's go back to the solution in #2522 instead to avoid expanding the problem further.

@jong-kyung

Copy link
Copy Markdown
Collaborator Author

This implementation is a bit over-engineered. The independently separated vp_global_only_cli crate is somewhat redundant. Let's go back to the solution in #2522 instead to avoid expanding the problem further.

Thanks for reviewing! That make sense, I wanted to make future global-only commands impossible to forget, but a separate crate is more machinery than that problem deserves. I'll close this PR and go back to #2522 🙇‍♂️

@jong-kyung jong-kyung closed this Aug 21, 2026
@jong-kyung
jong-kyung deleted the refactor/extract-global-only-commands branch August 21, 2026 15:24
fengmk2 pushed a commit that referenced this pull request Aug 22, 2026
The Command Routing section of `rfcs/merge-global-and-local-cli.md`
still described the two-path model from the original merge: Category A
for package-manager commands and Category B for "everything else".
`crates/vp_global_cli/src/cli.rs` has since grown into three labelled
blocks plus a handful of Rust-native commands, so the RFC no longer
matched the code it documents.

This rewrites the section to mirror `cli.rs` as it is today:

- Category A (package manager), B (JS script commands: `create`,
`migrate`, `config`, `hooks`, `staged`, `--version`), and C (local CLI
delegation: `dev` through `cache`), matching the comment blocks in the
`Commands` enum.
- A separate "Rust-native global commands" group for the variants
outside those blocks: `toolchain` as a hybrid that delegates locally or
renders the global `toolchain.json` depending on `--global`, `env`, and
the self-management pair `upgrade` and `implode`.
- The `--global` interception for package-manager commands now points at
`PackageManagerCommand::managed_global_command` and `commands::global`;
the RFC still referenced the removed `commands::env::global_install`.
- The ASCII diagram is replaced with a mermaid flowchart, which the repo
already uses in `docs/` and `rfcs/core-binding-resolution.md`, so the B
and C convergence on `oxc_resolver` and the `--global` branches are
visible.

Docs only, no code changes. Follows up on the routing gaps surfaced
while reviewing #2525.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants