@@ -183,9 +183,9 @@ pub struct Flags {
183183}
184184
185185impl 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 {
189189 // We need to check for `<cmd> -h -v`, in which case we list the paths
190190 #[ derive( Parser ) ]
191191 #[ command( disable_help_flag( true ) ) ]
@@ -198,24 +198,34 @@ impl Flags {
198198 cmd : Kind ,
199199 }
200200 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 ) )
202202 {
203203 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" ) ] ) ) ;
205205 let build = Build :: new ( config) ;
206206 let paths = Builder :: get_help ( & build, subcommand) ;
207207 if let Some ( s) = paths {
208208 println ! ( "{s}" ) ;
209209 } else {
210210 panic ! ( "No paths available for subcommand `{}`" , subcommand. as_str( ) ) ;
211211 }
212- crate :: exit!( 0 ) ;
212+ true
213+ } else {
214+ false
213215 }
216+ }
214217
215- Flags :: parse_from ( it)
218+ pub fn parse ( args : & [ String ] ) -> Self {
219+ Flags :: parse_from ( normalize_args ( args) )
216220 }
217221}
218222
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+
219229#[ derive( Debug , Clone , Default , clap:: Subcommand ) ]
220230pub enum Subcommand {
221231 #[ command( aliases = [ "b" ] , long_about = "\n
0 commit comments