@@ -257,8 +257,8 @@ int parse_options_end(struct parse_opt_ctx_t *ctx)
257
257
return ctx -> cpidx + ctx -> argc ;
258
258
}
259
259
260
- static NORETURN void usage_with_options_internal (const char * const * ,
261
- const struct option * , int );
260
+ static int usage_with_options_internal (const char * const * ,
261
+ const struct option * , int , int );
262
262
263
263
int parse_options (int argc , const char * * argv , const struct option * options ,
264
264
const char * const usagestr [], int flags )
@@ -302,7 +302,7 @@ int parse_options(int argc, const char **argv, const struct option *options,
302
302
}
303
303
304
304
if (!strcmp (arg + 2 , "help-all" ))
305
- usage_with_options_internal (usagestr , options , 1 );
305
+ usage_with_options_internal (usagestr , options , 1 , 1 );
306
306
if (!strcmp (arg + 2 , "help" ))
307
307
usage_with_options (usagestr , options );
308
308
if (parse_long_opt (& ctx , arg + 2 , options ))
@@ -315,8 +315,8 @@ int parse_options(int argc, const char **argv, const struct option *options,
315
315
#define USAGE_OPTS_WIDTH 24
316
316
#define USAGE_GAP 2
317
317
318
- void usage_with_options_internal (const char * const * usagestr ,
319
- const struct option * opts , int full )
318
+ int usage_with_options_internal (const char * const * usagestr ,
319
+ const struct option * opts , int full , int do_exit )
320
320
{
321
321
fprintf (stderr , "usage: %s\n" , * usagestr ++ );
322
322
while (* usagestr && * * usagestr )
@@ -401,15 +401,25 @@ void usage_with_options_internal(const char * const *usagestr,
401
401
}
402
402
fputc ('\n' , stderr );
403
403
404
- exit (129 );
404
+ if (do_exit )
405
+ exit (129 );
406
+ return PARSE_OPT_HELP ;
405
407
}
406
408
407
409
void usage_with_options (const char * const * usagestr ,
408
410
const struct option * opts )
409
411
{
410
- usage_with_options_internal (usagestr , opts , 0 );
412
+ usage_with_options_internal (usagestr , opts , 0 , 1 );
413
+ exit (129 ); /* make gcc happy */
411
414
}
412
415
416
+ int parse_options_usage (const char * const * usagestr ,
417
+ const struct option * opts )
418
+ {
419
+ return usage_with_options_internal (usagestr , opts , 0 , 0 );
420
+ }
421
+
422
+
413
423
/*----- some often used options -----*/
414
424
#include "cache.h"
415
425
0 commit comments