@@ -9,6 +9,7 @@ pub type Result<T> = result::Result<T, UtilsArgParserError>;
9
9
const ARG_PREFIX : & str = "--" ;
10
10
const ARG_SEPARATOR : & str = "--" ;
11
11
const HELP_ARG : & str = "--help" ;
12
+ const SHORT_HELP_ARG : & str = "-h" ;
12
13
const VERSION_ARG : & str = "--version" ;
13
14
14
15
/// Errors associated with parsing and validating arguments.
@@ -330,10 +331,10 @@ impl<'a> Arguments<'a> {
330
331
let ( args, extra_args) = Arguments :: split_args ( & args[ 1 ..] ) ;
331
332
self . extra_args = extra_args. to_vec ( ) ;
332
333
333
- // If `--help` is provided as a parameter, we artificially skip the parsing of other
334
+ // If `--help` or `-h` is provided as a parameter, we artificially skip the parsing of other
334
335
// command line arguments by adding just the help argument to the parsed list and
335
336
// returning.
336
- if args. contains ( & HELP_ARG . to_string ( ) ) {
337
+ if args. contains ( & HELP_ARG . to_string ( ) ) || args . contains ( & SHORT_HELP_ARG . to_string ( ) ) {
337
338
let mut help_arg = Argument :: new ( "help" ) . help ( "Show the help message." ) ;
338
339
help_arg. user_value = Some ( Value :: Flag ) ;
339
340
self . insert_arg ( help_arg) ;
@@ -652,6 +653,16 @@ mod tests {
652
653
653
654
arguments = arg_parser. arguments ( ) . clone ( ) ;
654
655
656
+ let args = vec ! [ "binary-name" , "--exec-file" , "foo" , "-h" ]
657
+ . into_iter ( )
658
+ . map ( String :: from)
659
+ . collect :: < Vec < String > > ( ) ;
660
+
661
+ arguments. parse ( & args) . unwrap ( ) ;
662
+ assert ! ( arguments. args. contains_key( "help" ) ) ;
663
+
664
+ arguments = arg_parser. arguments ( ) . clone ( ) ;
665
+
655
666
let args = vec ! [ "binary-name" , "--exec-file" , "foo" , "--version" ]
656
667
. into_iter ( )
657
668
. map ( String :: from)
0 commit comments