@@ -435,6 +435,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
435
435
const char * const usagestr [])
436
436
{
437
437
int internal_help = !(ctx -> flags & PARSE_OPT_NO_INTERNAL_HELP );
438
+ int err = 0 ;
438
439
439
440
/* we must reset ->opt, unknown short option leave it dangling */
440
441
ctx -> opt = NULL ;
@@ -454,10 +455,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
454
455
if (arg [1 ] != '-' ) {
455
456
ctx -> opt = arg + 1 ;
456
457
if (internal_help && * ctx -> opt == 'h' )
457
- return parse_options_usage ( ctx , usagestr , options , 0 ) ;
458
+ goto show_usage ;
458
459
switch (parse_short_opt (ctx , options )) {
459
460
case -1 :
460
- return parse_options_usage ( ctx , usagestr , options , 1 ) ;
461
+ goto show_usage_error ;
461
462
case -2 :
462
463
if (ctx -> opt )
463
464
check_typos (arg + 1 , options );
@@ -467,10 +468,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
467
468
check_typos (arg + 1 , options );
468
469
while (ctx -> opt ) {
469
470
if (internal_help && * ctx -> opt == 'h' )
470
- return parse_options_usage ( ctx , usagestr , options , 0 ) ;
471
+ goto show_usage ;
471
472
switch (parse_short_opt (ctx , options )) {
472
473
case -1 :
473
- return parse_options_usage ( ctx , usagestr , options , 1 ) ;
474
+ goto show_usage_error ;
474
475
case -2 :
475
476
/* fake a short option thing to hide the fact that we may have
476
477
* started to parse aggregated stuff
@@ -496,10 +497,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
496
497
if (internal_help && !strcmp (arg + 2 , "help-all" ))
497
498
return usage_with_options_internal (ctx , usagestr , options , 1 , 0 );
498
499
if (internal_help && !strcmp (arg + 2 , "help" ))
499
- return parse_options_usage ( ctx , usagestr , options , 0 ) ;
500
+ goto show_usage ;
500
501
switch (parse_long_opt (ctx , arg + 2 , options )) {
501
502
case -1 :
502
- return parse_options_usage ( ctx , usagestr , options , 1 ) ;
503
+ goto show_usage_error ;
503
504
case -2 :
504
505
goto unknown ;
505
506
}
@@ -511,6 +512,11 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
511
512
ctx -> opt = NULL ;
512
513
}
513
514
return PARSE_OPT_DONE ;
515
+
516
+ show_usage_error :
517
+ err = 1 ;
518
+ show_usage :
519
+ return parse_options_usage (ctx , usagestr , options , err );
514
520
}
515
521
516
522
int parse_options_end (struct parse_opt_ctx_t * ctx )
0 commit comments