@@ -435,6 +435,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
435435 const char * const usagestr [])
436436{
437437 int internal_help = !(ctx -> flags & PARSE_OPT_NO_INTERNAL_HELP );
438+ int err = 0 ;
438439
439440 /* we must reset ->opt, unknown short option leave it dangling */
440441 ctx -> opt = NULL ;
@@ -454,10 +455,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
454455 if (arg [1 ] != '-' ) {
455456 ctx -> opt = arg + 1 ;
456457 if (internal_help && * ctx -> opt == 'h' )
457- return parse_options_usage ( ctx , usagestr , options , 0 ) ;
458+ goto show_usage ;
458459 switch (parse_short_opt (ctx , options )) {
459460 case -1 :
460- return parse_options_usage ( ctx , usagestr , options , 1 ) ;
461+ goto show_usage_error ;
461462 case -2 :
462463 if (ctx -> opt )
463464 check_typos (arg + 1 , options );
@@ -467,10 +468,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
467468 check_typos (arg + 1 , options );
468469 while (ctx -> opt ) {
469470 if (internal_help && * ctx -> opt == 'h' )
470- return parse_options_usage ( ctx , usagestr , options , 0 ) ;
471+ goto show_usage ;
471472 switch (parse_short_opt (ctx , options )) {
472473 case -1 :
473- return parse_options_usage ( ctx , usagestr , options , 1 ) ;
474+ goto show_usage_error ;
474475 case -2 :
475476 /* fake a short option thing to hide the fact that we may have
476477 * started to parse aggregated stuff
@@ -496,10 +497,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
496497 if (internal_help && !strcmp (arg + 2 , "help-all" ))
497498 return usage_with_options_internal (ctx , usagestr , options , 1 , 0 );
498499 if (internal_help && !strcmp (arg + 2 , "help" ))
499- return parse_options_usage ( ctx , usagestr , options , 0 ) ;
500+ goto show_usage ;
500501 switch (parse_long_opt (ctx , arg + 2 , options )) {
501502 case -1 :
502- return parse_options_usage ( ctx , usagestr , options , 1 ) ;
503+ goto show_usage_error ;
503504 case -2 :
504505 goto unknown ;
505506 }
@@ -511,6 +512,11 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
511512 ctx -> opt = NULL ;
512513 }
513514 return PARSE_OPT_DONE ;
515+
516+ show_usage_error :
517+ err = 1 ;
518+ show_usage :
519+ return parse_options_usage (ctx , usagestr , options , err );
514520}
515521
516522int parse_options_end (struct parse_opt_ctx_t * ctx )
0 commit comments