diff options
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | 2009-03-08 19:12:47 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-03-08 13:36:09 -0700 |
commit | b5ce3a54302cb6e29a02cd8fe4ea55eacea0a86e (patch) | |
tree | 8b645fabe497f906af064488b8f7d2c8d171800d | |
parent | Merge branch 'maint' (diff) | |
download | tgif-b5ce3a54302cb6e29a02cd8fe4ea55eacea0a86e.tar.xz |
parseopt: add PARSE_OPT_KEEP_UNKNOWN
Add a parseopt flag, PARSE_OPT_KEEP_UNKNOWN, that can be used to keep
unknown options in argv, similar to the existing KEEP flags.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | parse-options.c | 12 | ||||
-rw-r--r-- | parse-options.h | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/parse-options.c b/parse-options.c index 4c5d09dd25..39808ae458 100644 --- a/parse-options.c +++ b/parse-options.c @@ -274,7 +274,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, case -1: return parse_options_usage(usagestr, options); case -2: - return PARSE_OPT_UNKNOWN; + goto unknown; } if (ctx->opt) check_typos(arg + 1, options); @@ -292,7 +292,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, */ ctx->argv[0] = xstrdup(ctx->opt - 1); *(char *)ctx->argv[0] = '-'; - return PARSE_OPT_UNKNOWN; + goto unknown; } } continue; @@ -314,8 +314,14 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, case -1: return parse_options_usage(usagestr, options); case -2: - return PARSE_OPT_UNKNOWN; + goto unknown; } + continue; +unknown: + if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN)) + return PARSE_OPT_UNKNOWN; + ctx->out[ctx->cpidx++] = ctx->argv[0]; + ctx->opt = NULL; } return PARSE_OPT_DONE; } diff --git a/parse-options.h b/parse-options.h index 912290549b..b7d08b13d1 100644 --- a/parse-options.h +++ b/parse-options.h @@ -21,6 +21,7 @@ enum parse_opt_flags { PARSE_OPT_KEEP_DASHDASH = 1, PARSE_OPT_STOP_AT_NON_OPTION = 2, PARSE_OPT_KEEP_ARGV0 = 4, + PARSE_OPT_KEEP_UNKNOWN = 8, }; enum parse_opt_option_flags { |