@matheusbsbs / matheus-bagliano / commits / b5ce3a5430
Fork 0

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>

René Scharfe committed Mar 8, 2009 at 19:12 UTC b5ce3a54302cb6e29a02cd8fe4ea55eacea0a86e
2 files changed +10 -3
parse-options.c
+9 -3
@@ -274,7 +274,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
274 case -1:
275 return parse_options_usage(usagestr, options);
276 case -2:
277 - return PARSE_OPT_UNKNOWN;
277 + goto unknown;
278 }
279 if (ctx->opt)
280 check_typos(arg + 1, options);
@@ -292,7 +292,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
292 */
293 ctx->argv[0] = xstrdup(ctx->opt - 1);
294 *(char *)ctx->argv[0] = '-';
295 - return PARSE_OPT_UNKNOWN;
295 + goto unknown;
296 }
297 }
298 continue;
@@ -314,8 +314,14 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
314 case -1:
315 return parse_options_usage(usagestr, options);
316 case -2:
317 - return PARSE_OPT_UNKNOWN;
317 + goto unknown;
318 }
319 + continue;
320 +unknown:
321 + if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN))
322 + return PARSE_OPT_UNKNOWN;
323 + ctx->out[ctx->cpidx++] = ctx->argv[0];
324 + ctx->opt = NULL;
325 }
326 return PARSE_OPT_DONE;
327 }
parse-options.h
+1
@@ -21,6 +21,7 @@ enum parse_opt_flags {
21 PARSE_OPT_KEEP_DASHDASH = 1,
22 PARSE_OPT_STOP_AT_NON_OPTION = 2,
23 PARSE_OPT_KEEP_ARGV0 = 4,
24 + PARSE_OPT_KEEP_UNKNOWN = 8,
25 };
26
27 enum parse_opt_option_flags {