@@ -183,9 +183,9 @@ pub struct Flags {
183
183
}
184
184
185
185
impl Flags {
186
- pub fn parse ( args : & [ String ] ) -> Self {
187
- let first = String :: from ( "x.py" ) ;
188
- let it = std :: iter :: once ( & first ) . chain ( args . iter ( ) ) ;
186
+ /// Check if `<cmd> -h -v` was passed.
187
+ /// If yes, print the available paths and return `true`.
188
+ pub fn try_parse_verbose_help ( args : & [ String ] ) -> bool {
189
189
// We need to check for `<cmd> -h -v`, in which case we list the paths
190
190
#[ derive( Parser ) ]
191
191
#[ command( disable_help_flag( true ) ) ]
@@ -198,24 +198,34 @@ impl Flags {
198
198
cmd : Kind ,
199
199
}
200
200
if let Ok ( HelpVerboseOnly { help : true , verbose : 1 .., cmd : subcommand } ) =
201
- HelpVerboseOnly :: try_parse_from ( it . clone ( ) )
201
+ HelpVerboseOnly :: try_parse_from ( normalize_args ( args ) )
202
202
{
203
203
println ! ( "NOTE: updating submodules before printing available paths" ) ;
204
- let config = Config :: parse ( & [ String :: from ( "build" ) ] ) ;
204
+ let config = Config :: parse ( Self :: parse ( & [ String :: from ( "build" ) ] ) ) ;
205
205
let build = Build :: new ( config) ;
206
206
let paths = Builder :: get_help ( & build, subcommand) ;
207
207
if let Some ( s) = paths {
208
208
println ! ( "{s}" ) ;
209
209
} else {
210
210
panic ! ( "No paths available for subcommand `{}`" , subcommand. as_str( ) ) ;
211
211
}
212
- crate :: exit!( 0 ) ;
212
+ true
213
+ } else {
214
+ false
213
215
}
216
+ }
214
217
215
- Flags :: parse_from ( it)
218
+ pub fn parse ( args : & [ String ] ) -> Self {
219
+ Flags :: parse_from ( normalize_args ( args) )
216
220
}
217
221
}
218
222
223
+ fn normalize_args ( args : & [ String ] ) -> Vec < String > {
224
+ let first = String :: from ( "x.py" ) ;
225
+ let it = std:: iter:: once ( first) . chain ( args. iter ( ) . cloned ( ) ) ;
226
+ it. collect ( )
227
+ }
228
+
219
229
#[ derive( Debug , Clone , Default , clap:: Subcommand ) ]
220
230
pub enum Subcommand {
221
231
#[ command( aliases = [ "b" ] , long_about = "\n
0 commit comments