11use std:: process:: ExitStatus ;
22
3- use clap:: { Parser , Subcommand } ;
3+ use clap:: { CommandFactory , Parser , Subcommand } ;
44use vite_error:: Error ;
55use vite_install:: commands:: {
66 add:: SaveDependencyType , install:: InstallCommandOptions , outdated:: Format ,
@@ -15,16 +15,7 @@ use crate::commands::{
1515
1616#[ derive( Parser , Debug ) ]
1717#[ clap( author, version, about, long_about = None ) ]
18- #[ command(
19- disable_help_subcommand = true ,
20- help_template = "\
21- vite+/{version}
22-
23- {usage-heading} {usage}
24-
25- {all-args}{after-help}
26- "
27- ) ]
18+ #[ command( disable_help_subcommand = true ) ]
2819pub struct Args {
2920 #[ clap( subcommand) ]
3021 pub commands : Commands ,
@@ -406,6 +397,24 @@ pub enum Commands {
406397 #[ arg( last = true , allow_hyphen_values = true ) ]
407398 pass_through_args : Option < Vec < String > > ,
408399 } ,
400+ /// View package information from registry
401+ #[ command( alias = "view" , alias = "show" ) ]
402+ Info {
403+ /// Package name with optional version
404+ #[ arg( required = true ) ]
405+ package : String ,
406+
407+ /// Specific field to view
408+ field : Option < String > ,
409+
410+ /// Output in JSON format
411+ #[ arg( long) ]
412+ json : bool ,
413+
414+ /// Additional arguments to pass through to the package manager
415+ #[ arg( last = true , allow_hyphen_values = true ) ]
416+ pass_through_args : Option < Vec < String > > ,
417+ } ,
409418 /// Link packages for local development
410419 #[ command( alias = "ln" ) ]
411420 Link {
@@ -433,7 +442,7 @@ pub enum Commands {
433442 #[ arg( allow_hyphen_values = true , trailing_var_arg = true ) ]
434443 args : Vec < String > ,
435444 } ,
436- /// Package manager utilities
445+ /// Forward command to the package manager.
437446 #[ command( subcommand) ]
438447 Pm ( PmCommands ) ,
439448 /// Execute a package binary without installing it as a dependency
@@ -1064,6 +1073,17 @@ pub async fn main(cwd: AbsolutePathBuf, mut args: Args) -> Result<std::process::
10641073 . await ?;
10651074 return Ok ( exit_status) ;
10661075 }
1076+ Commands :: Info { package, field, json, pass_through_args } => {
1077+ let exit_status = PmCommand :: new ( cwd)
1078+ . execute ( PmCommands :: View {
1079+ package : package. clone ( ) ,
1080+ field : field. clone ( ) ,
1081+ json : * json,
1082+ pass_through_args : pass_through_args. clone ( ) ,
1083+ } )
1084+ . await ?;
1085+ return Ok ( exit_status) ;
1086+ }
10671087 Commands :: Pm ( pm_command) => {
10681088 let exit_status = PmCommand :: new ( cwd) . execute ( pm_command. clone ( ) ) . await ?;
10691089 return Ok ( exit_status) ;
@@ -1078,6 +1098,53 @@ pub async fn main(cwd: AbsolutePathBuf, mut args: Args) -> Result<std::process::
10781098 } ;
10791099}
10801100
1101+ pub fn command_with_help ( ) -> clap:: Command {
1102+ let bold = "\x1b [1m" ;
1103+ let bold_underline = "\x1b [1;4m" ;
1104+ let reset = "\x1b [0m" ;
1105+ let version = env ! ( "CARGO_PKG_VERSION" ) ;
1106+
1107+ let after_help = format ! (
1108+ "{bold_underline}Vite+ Commands:{reset}
1109+ {bold}dev{reset} Run development server
1110+ {bold}build{reset} Build for production
1111+ {bold}lint{reset} Lint code
1112+ {bold}test{reset} Run tests
1113+ {bold}fmt{reset} Format code
1114+ {bold}doc{reset} Build documentation
1115+ {bold}lib{reset} Build library
1116+ {bold}migrate{reset} Migrate an existing project to Vite+
1117+ {bold}cache{reset} Manage the task cache
1118+ {bold}new{reset} Generate a new project
1119+ {bold}run{reset} Run tasks
1120+
1121+ {bold_underline}Package Manager Commands:{reset}
1122+ {bold}install{reset} Install all dependencies, or add packages if package names are provided
1123+ {bold}add{reset} Add packages to dependencies
1124+ {bold}remove{reset} Remove packages from dependencies
1125+ {bold}dedupe{reset} Deduplicate dependencies by removing older versions
1126+ {bold}dlx{reset} Execute a package binary without installing it as a dependency
1127+ {bold}info{reset} View package information from registry
1128+ {bold}link{reset} Link packages for local development
1129+ {bold}outdated{reset} Check for outdated packages
1130+ {bold}pm{reset} Forward command to the package manager
1131+ {bold}unlink{reset} Unlink packages
1132+ {bold}update{reset} Update packages to their latest versions
1133+ {bold}why{reset} Show why a package is installed
1134+ "
1135+ ) ;
1136+ let help_template = format ! (
1137+ "vite+/{version}
1138+
1139+ {{usage-heading}} {{usage}}{{after-help}}
1140+ {bold_underline}Options:{reset}
1141+ {{options}}
1142+ "
1143+ ) ;
1144+
1145+ Args :: command ( ) . after_help ( after_help) . help_template ( help_template)
1146+ }
1147+
10811148pub fn init_tracing ( ) {
10821149 use std:: sync:: OnceLock ;
10831150
0 commit comments