1- use clap:: { value_parser , Arg , ArgAction , Command } ;
1+ use clap:: { Arg , ArgAction , Command } ;
22use serde_json:: Value ;
33use std:: fs;
44use std:: io:: { BufRead , BufReader } ;
@@ -18,18 +18,13 @@ fn main() {
1818 println ! ( "👏 Package manage tool is {} , the version is {}" , p, v) ;
1919 let matches = Command :: new ( "n" )
2020 . subcommand (
21- Command :: new ( "i" )
22- . about ( "Install operations" )
23- . arg (
24- Arg :: new ( "frozen" )
25- . long ( "frozen" )
26- . exclusive ( true )
27- . default_missing_value ( "true" )
28- . num_args ( 0 ..=1 )
29- . value_parser ( value_parser ! ( bool ) ) ,
30- )
31- . arg ( Arg :: new ( "package" ) . required ( false ) ) ,
21+ Command :: new ( "i" ) . about ( "Install operations" ) . arg (
22+ Arg :: new ( "package" )
23+ . required ( false )
24+ . action ( ArgAction :: Append ) ,
25+ ) ,
3226 )
27+ . subcommand ( Command :: new ( "ci" ) )
3328 . subcommand (
3429 Command :: new ( "r" )
3530 . about ( "Running script" )
@@ -45,18 +40,24 @@ fn main() {
4540 // Then you can check which subcommand was used
4641 match matches. subcommand ( ) {
4742 Some ( ( "i" , i_matches) ) => {
48- if let Some ( frozen) = i_matches. get_one :: < bool > ( "frozen" ) {
49- if * frozen {
50- run_install_command ( p, vec ! [ "install" , "--frozen-lockfile" ] )
51- } else {
52- run_install_command ( p, vec ! [ "install" ] )
53- }
54- } else if let Some ( package) = i_matches. get_one :: < String > ( "package" ) {
43+ if let Some ( package) = i_matches. get_one :: < String > ( "package" ) {
5544 run_install_command ( p, vec ! [ "install" , package] )
5645 } else {
5746 run_install_command ( p, vec ! [ "install" ] )
5847 }
5948 }
49+ Some ( ( "ci" , _ci_matches) ) => match p. as_str ( ) {
50+ "npm" => {
51+ run_install_command ( p, vec ! [ "ci" ] ) ;
52+ }
53+ "pnpm" => {
54+ run_install_command ( p, vec ! [ "install" , "--frozen-lockfile" ] ) ;
55+ }
56+ "yarn" => {
57+ run_install_command ( p, vec ! [ "install" , "--frozen-lockfile" ] ) ;
58+ }
59+ _ => { }
60+ } ,
6061 Some ( ( "r" , r_matches) ) => match r_matches. get_one :: < String > ( "script" ) {
6162 Some ( script) => {
6263 run_install_command ( p, vec ! [ script] ) ;
0 commit comments