Skip to content

Commit 979240f

Browse files
jrngitster
authored andcommitted
parse-options: make resuming easier after PARSE_OPT_STOP_AT_NON_OPTION
Introduce a PARSE_OPT_NON_OPTION state, so parse_option_step() callers can easily distinguish between non-options and other reasons for option parsing termination (like "--"). Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0b3a8b commit 979240f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

parse-options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
373373
if (parse_nodash_opt(ctx, arg, options) == 0)
374374
continue;
375375
if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
376-
break;
376+
return PARSE_OPT_NON_OPTION;
377377
ctx->out[ctx->cpidx++] = ctx->argv[0];
378378
continue;
379379
}
@@ -455,6 +455,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
455455
switch (parse_options_step(&ctx, options, usagestr)) {
456456
case PARSE_OPT_HELP:
457457
exit(129);
458+
case PARSE_OPT_NON_OPTION:
458459
case PARSE_OPT_DONE:
459460
break;
460461
default: /* PARSE_OPT_UNKNOWN */

parse-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
167167
enum {
168168
PARSE_OPT_HELP = -1,
169169
PARSE_OPT_DONE,
170+
PARSE_OPT_NON_OPTION,
170171
PARSE_OPT_UNKNOWN
171172
};
172173

0 commit comments

Comments
 (0)