11use  anyhow:: Result ; 
2- use  clap:: { arg ,   Arg ,   ArgAction ,   Args ,   FromArgMatches ,   Parser ,  ValueEnum } ; 
2+ use  clap:: { Parser ,  ValueEnum } ; 
33use  clap_verbosity_flag:: InfoLevel ; 
44use  log:: LevelFilter ; 
55use  regex:: Regex ; 
@@ -26,7 +26,7 @@ enum Command {
2626/// default build system fails to pick up changed interfaces across multiple packages. 
2727#[ derive( Parser ,  Debug ) ]  
2828#[ command( version) ]  
29- struct  DerivedArgs  { 
29+ struct  Args  { 
3030    #[ arg( value_enum,  default_value_t = Command :: Build ) ]  
3131    command :  Command , 
3232
@@ -84,36 +84,25 @@ struct DerivedArgs {
8484    /// A custom path to bsc 
8585#[ arg( long) ]  
8686    bsc_path :  Option < String > , 
87+ 
88+     /// Use the legacy build system. 
89+ /// 
90+ /// After this flag is encountered, the rest of the command line arguments are passed to the legacy build system. 
91+ #[ arg( long,  allow_hyphen_values = true ,  num_args = 0 ..) ]  
92+     legacy :  Vec < String > , 
8793} 
8894
8995fn  main ( )  -> Result < ( ) >  { 
90-     let  legacy = clap:: Command :: new ( "rewatch" ) 
91-         . disable_help_flag ( true ) 
92-         . disable_version_flag ( true ) 
93-         . arg ( 
94-             arg ! ( -l - -legacy ... "Use the legacy build system" ) 
95-                 . global ( true ) 
96-                 . action ( ArgAction :: SetTrue ) , 
97-         ) 
98-         . defer ( |cmd| { 
99-             cmd. arg ( arg ! ( [ cmd]  ... "commands and args for the legacy build system" ) . trailing_var_arg ( true ) ) 
100-         } ) ; 
101- 
102-     let  legacy_matches = legacy. get_matches ( ) ; 
103- 
104-     if  legacy_matches. get_flag ( "legacy" )  { 
96+     let  args = Args :: parse ( ) ; 
97+ 
98+     if  !args. legacy . is_empty ( )  { 
10599        let  s = std:: env:: args ( ) . collect :: < Vec < String > > ( ) . join ( " " ) ; 
106100
107101        println ! ( "Using legacy build system" ) ; 
108102        println ! ( "Running: {s}" ) ; 
109103        std:: process:: exit ( 0 ) ; 
110104    } 
111105
112-     let  matches = DerivedArgs :: augment_args ( clap:: Command :: new ( "rewatch" ) ) . get_matches ( ) ; 
113-     let  args = DerivedArgs :: from_arg_matches ( & matches) 
114-         . map_err ( |err| err. exit ( ) ) 
115-         . unwrap ( ) ; 
116- 
117106    let  log_level_filter = args. verbose . log_level_filter ( ) ; 
118107
119108    env_logger:: Builder :: new ( ) 
0 commit comments