@@ -17,6 +17,7 @@ use crate::{
1717 RemoveCommand , UnlinkCommand , UpdateCommand , WhyCommand ,
1818 } ,
1919 error:: Error ,
20+ help,
2021} ;
2122
2223/// Vite+ Global CLI
@@ -1793,25 +1794,65 @@ pub async fn run_command(cwd: AbsolutePathBuf, args: Args) -> Result<ExitStatus,
17931794 Commands :: Migrate { args } => commands:: migrate:: execute ( cwd, & args) . await ,
17941795
17951796 // Category C: Local CLI Delegation (stubs)
1796- Commands :: Dev { args } => commands:: delegate:: execute ( cwd, "dev" , & args) . await ,
1797+ Commands :: Dev { args } => {
1798+ if help:: maybe_print_unified_delegate_help ( "dev" , & args) {
1799+ return Ok ( ExitStatus :: default ( ) ) ;
1800+ }
1801+ commands:: delegate:: execute ( cwd, "dev" , & args) . await
1802+ }
17971803
1798- Commands :: Build { args } => commands:: delegate:: execute ( cwd, "build" , & args) . await ,
1804+ Commands :: Build { args } => {
1805+ if help:: maybe_print_unified_delegate_help ( "build" , & args) {
1806+ return Ok ( ExitStatus :: default ( ) ) ;
1807+ }
1808+ commands:: delegate:: execute ( cwd, "build" , & args) . await
1809+ }
17991810
1800- Commands :: Test { args } => commands:: delegate:: execute ( cwd, "test" , & args) . await ,
1811+ Commands :: Test { args } => {
1812+ if help:: maybe_print_unified_delegate_help ( "test" , & args) {
1813+ return Ok ( ExitStatus :: default ( ) ) ;
1814+ }
1815+ commands:: delegate:: execute ( cwd, "test" , & args) . await
1816+ }
18011817
1802- Commands :: Lint { args } => commands:: delegate:: execute ( cwd, "lint" , & args) . await ,
1818+ Commands :: Lint { args } => {
1819+ if help:: maybe_print_unified_delegate_help ( "lint" , & args) {
1820+ return Ok ( ExitStatus :: default ( ) ) ;
1821+ }
1822+ commands:: delegate:: execute ( cwd, "lint" , & args) . await
1823+ }
18031824
1804- Commands :: Fmt { args } => commands:: delegate:: execute ( cwd, "fmt" , & args) . await ,
1825+ Commands :: Fmt { args } => {
1826+ if help:: maybe_print_unified_delegate_help ( "fmt" , & args) {
1827+ return Ok ( ExitStatus :: default ( ) ) ;
1828+ }
1829+ commands:: delegate:: execute ( cwd, "fmt" , & args) . await
1830+ }
18051831
1806- Commands :: Check { args } => commands:: delegate:: execute ( cwd, "check" , & args) . await ,
1832+ Commands :: Check { args } => {
1833+ if help:: maybe_print_unified_delegate_help ( "check" , & args) {
1834+ return Ok ( ExitStatus :: default ( ) ) ;
1835+ }
1836+ commands:: delegate:: execute ( cwd, "check" , & args) . await
1837+ }
18071838
1808- Commands :: Pack { args } => commands:: delegate:: execute ( cwd, "pack" , & args) . await ,
1839+ Commands :: Pack { args } => {
1840+ if help:: maybe_print_unified_delegate_help ( "pack" , & args) {
1841+ return Ok ( ExitStatus :: default ( ) ) ;
1842+ }
1843+ commands:: delegate:: execute ( cwd, "pack" , & args) . await
1844+ }
18091845
18101846 Commands :: Run { args } => commands:: run_or_delegate:: execute ( cwd, & args) . await ,
18111847
18121848 Commands :: Exec { args } => commands:: delegate:: execute ( cwd, "exec" , & args) . await ,
18131849
1814- Commands :: Preview { args } => commands:: delegate:: execute ( cwd, "preview" , & args) . await ,
1850+ Commands :: Preview { args } => {
1851+ if help:: maybe_print_unified_delegate_help ( "preview" , & args) {
1852+ return Ok ( ExitStatus :: default ( ) ) ;
1853+ }
1854+ commands:: delegate:: execute ( cwd, "preview" , & args) . await
1855+ }
18151856
18161857 Commands :: Cache { args } => commands:: delegate:: execute ( cwd, "cache" , & args) . await ,
18171858
@@ -1854,52 +1895,12 @@ pub fn command_with_help() -> clap::Command {
18541895
18551896/// Apply custom help formatting to a clap Command to match the JS CLI output.
18561897fn apply_custom_help ( cmd : clap:: Command ) -> clap:: Command {
1857- let bold = "\x1b [1m" ;
1858- let bold_underline = "\x1b [1;4m" ;
1859- let reset = "\x1b [0m" ;
18601898 let version = env ! ( "CARGO_PKG_VERSION" ) ;
1861-
1862- let after_help = format ! (
1863- "{bold_underline}Core Commands:{reset}
1864- {bold}create{reset} Create a new project from a template
1865- {bold}dev{reset} Run the development server
1866- {bold}build{reset} Build for production
1867- {bold}test{reset} Run tests
1868- {bold}lint{reset} Lint code
1869- {bold}fmt{reset} Format code
1870- {bold}check{reset} Run format, lint, and type checks
1871- {bold}pack{reset} Build library
1872- {bold}run{reset} Run tasks
1873- {bold}exec{reset} Execute a command from local node_modules/.bin
1874- {bold}preview{reset} Preview production build
1875- {bold}env{reset} Manage Node.js versions
1876- {bold}migrate{reset} Migrate an existing project to Vite+
1877- {bold}cache{reset} Manage the task cache
1878-
1879- {bold_underline}Package Manager Commands:{reset}
1880- {bold}install, i{reset} Install all dependencies, or add packages if package names are provided
1881- {bold}add{reset} Add packages to dependencies
1882- {bold}remove, rm, un, uninstall{reset} Remove packages from dependencies
1883- {bold}dedupe{reset} Deduplicate dependencies by removing older versions
1884- {bold}dlx{reset} Execute a package binary without installing it as a dependency
1885- {bold}info, view, show{reset} View package information from the registry
1886- {bold}link, ln{reset} Link packages for local development
1887- {bold}list, ls{reset} List installed packages
1888- {bold}outdated{reset} Check for outdated packages
1889- {bold}pm{reset} Forward a command to the package manager
1890- {bold}unlink{reset} Unlink packages
1891- {bold}update, up{reset} Update packages to their latest versions
1892- {bold}why, explain{reset} Show why a package is installed
1893-
1894- {bold_underline}Maintenance Commands:{reset}
1895- {bold}upgrade{reset} Update vp itself to the latest version
1896- "
1897- ) ;
1899+ let after_help = help:: render_help_doc ( & help:: top_level_help_doc ( ) ) ;
18981900 let help_template = format ! (
1899- "Vite+/{version}
1900-
1901- {{usage-heading}} {{usage}}{{after-help}}
1902- {bold_underline}Options:{reset}
1901+ "Vite+/{version}\
1902+ {{after-help}}
1903+ Options:
19031904{{options}}
19041905"
19051906 ) ;
0 commit comments