Code

parse-options: make resuming easier after PARSE_OPT_STOP_AT_NON_OPTION
authorJonathan Nieder <jrnieder@gmail.com>
Wed, 1 Dec 2010 23:32:55 +0000 (17:32 -0600)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Dec 2010 22:19:32 +0000 (14:19 -0800)
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 <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c
parse-options.h

index cd926869166fe28d4c116840be6921de7aa3cbda..42b51ef14514f3c3df454e4b718718a9b58f1612 100644 (file)
@@ -373,7 +373,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                        if (parse_nodash_opt(ctx, arg, options) == 0)
                                continue;
                        if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
-                               break;
+                               return PARSE_OPT_NON_OPTION;
                        ctx->out[ctx->cpidx++] = ctx->argv[0];
                        continue;
                }
@@ -455,6 +455,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
        switch (parse_options_step(&ctx, options, usagestr)) {
        case PARSE_OPT_HELP:
                exit(129);
+       case PARSE_OPT_NON_OPTION:
        case PARSE_OPT_DONE:
                break;
        default: /* PARSE_OPT_UNKNOWN */
index 470bb33298bbeba6ae650f926d390233d0ee8d9f..3c2ec1d092202ca6468938e09894447baf409808 100644 (file)
@@ -167,6 +167,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
 enum {
        PARSE_OPT_HELP = -1,
        PARSE_OPT_DONE,
+       PARSE_OPT_NON_OPTION,
        PARSE_OPT_UNKNOWN
 };