1
1
use anyhow:: Result ;
2
- use clap:: { arg , Arg , ArgAction , Args , FromArgMatches , Parser , ValueEnum } ;
2
+ use clap:: { Parser , ValueEnum } ;
3
3
use clap_verbosity_flag:: InfoLevel ;
4
4
use log:: LevelFilter ;
5
5
use regex:: Regex ;
@@ -26,7 +26,7 @@ enum Command {
26
26
/// default build system fails to pick up changed interfaces across multiple packages.
27
27
#[ derive( Parser , Debug ) ]
28
28
#[ command( version) ]
29
- struct DerivedArgs {
29
+ struct Args {
30
30
#[ arg( value_enum, default_value_t = Command :: Build ) ]
31
31
command : Command ,
32
32
@@ -84,36 +84,25 @@ struct DerivedArgs {
84
84
/// A custom path to bsc
85
85
#[ arg( long) ]
86
86
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 > ,
87
93
}
88
94
89
95
fn 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 ( ) {
105
99
let s = std:: env:: args ( ) . collect :: < Vec < String > > ( ) . join ( " " ) ;
106
100
107
101
println ! ( "Using legacy build system" ) ;
108
102
println ! ( "Running: {s}" ) ;
109
103
std:: process:: exit ( 0 ) ;
110
104
}
111
105
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
-
117
106
let log_level_filter = args. verbose . log_level_filter ( ) ;
118
107
119
108
env_logger:: Builder :: new ( )
0 commit comments