@@ -31,23 +31,29 @@ pub fn parse_from_argv<I, T>(argv: I) -> Result<Options, ArgsError>
3131 // in order to pick the parser with or without subcommands.
3232 let parser = {
3333 // Determine whether the first non-flag argument is one of the gist commands.
34- let first_arg = argv. iter ( ) . skip ( 1 )
34+ let maybe_first_arg = argv. iter ( ) . skip ( 1 )
3535 . map ( |arg| {
3636 let arg: OsString = arg. clone ( ) . into ( ) ;
3737 arg. into_string ( ) . unwrap_or_else ( |_| String :: new ( ) )
3838 } )
39- . find ( |arg| !arg. starts_with ( "-" ) )
40- . unwrap_or_else ( || String :: new ( ) ) ;
41-
42- // If it is, use the full argument parser which recognizes those commands.
43- match Command :: from_str ( & first_arg) {
44- Ok ( _) => create_full_parser ( ) ,
45- Err ( _) => {
46- // If it's not, the parser will already have "run" command baked in.
47- let mut parser = create_parser_base ( ) ;
48- parser = configure_run_gist_parser ( parser) ;
49- parser
50- } ,
39+ . find ( |arg| !arg. starts_with ( "-" ) ) ;
40+
41+ // (That is, provided we got a positional argument at all).
42+ if let Some ( first_arg) = maybe_first_arg {
43+ match Command :: from_str ( & first_arg) {
44+ Ok ( _) => create_full_parser ( ) ,
45+ Err ( _) => {
46+ // If it's not a gist command, the parser we'll use
47+ // will already have "run" command baked in.
48+ let mut parser = create_parser_base ( ) ;
49+ parser = configure_run_gist_parser ( parser) ;
50+ parser
51+ } ,
52+ }
53+ } else {
54+ // If we only got flag arguments, use the full parser (with subcommands).
55+ // This ensure the correct help/usage instructions are shown.
56+ create_full_parser ( )
5157 }
5258 } ;
5359
0 commit comments