diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-04-10 16:28:20 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-04-10 16:28:20 +0900 |
commit | 62c0fd46a875050e904831a73ef4375ed26cfaf6 (patch) | |
tree | 9bb09418c52e02a93f55c62826574ad26ac20f5b /parse-options.c | |
parent | The first batch for 2.18 cycle (diff) | |
parent | parse-options: do not show usage upon invalid option value (diff) | |
download | tgif-62c0fd46a875050e904831a73ef4375ed26cfaf6.tar.xz |
Merge branch 'ps/contains-id-error-message'
"git tag --contains no-such-commit" gave a full list of options
after giving an error message.
* ps/contains-id-error-message:
parse-options: do not show usage upon invalid option value
Diffstat (limited to 'parse-options.c')
-rw-r--r-- | parse-options.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/parse-options.c b/parse-options.c index 125e84f984..0f7059a8ab 100644 --- a/parse-options.c +++ b/parse-options.c @@ -317,14 +317,16 @@ is_abbreviated: return get_value(p, options, all_opts, flags ^ opt_flags); } - if (ambiguous_option) - return error("Ambiguous option: %s " + if (ambiguous_option) { + error("Ambiguous option: %s " "(could be --%s%s or --%s%s)", arg, (ambiguous_flags & OPT_UNSET) ? "no-" : "", ambiguous_option->long_name, (abbrev_flags & OPT_UNSET) ? "no-" : "", abbrev_option->long_name); + return -3; + } if (abbrev_option) return get_value(p, abbrev_option, all_opts, abbrev_flags); return -2; @@ -476,7 +478,6 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, const char * const usagestr[]) { int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP); - int err = 0; /* we must reset ->opt, unknown short option leave it dangling */ ctx->opt = NULL; @@ -505,7 +506,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, ctx->opt = arg + 1; switch (parse_short_opt(ctx, options)) { case -1: - goto show_usage_error; + return PARSE_OPT_ERROR; case -2: if (ctx->opt) check_typos(arg + 1, options); @@ -518,7 +519,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, while (ctx->opt) { switch (parse_short_opt(ctx, options)) { case -1: - goto show_usage_error; + return PARSE_OPT_ERROR; case -2: if (internal_help && *ctx->opt == 'h') goto show_usage; @@ -550,9 +551,11 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, goto show_usage; switch (parse_long_opt(ctx, arg + 2, options)) { case -1: - goto show_usage_error; + return PARSE_OPT_ERROR; case -2: goto unknown; + case -3: + goto show_usage; } continue; unknown: @@ -563,10 +566,8 @@ unknown: } return PARSE_OPT_DONE; - show_usage_error: - err = 1; show_usage: - return usage_with_options_internal(ctx, usagestr, options, 0, err); + return usage_with_options_internal(ctx, usagestr, options, 0, 0); } int parse_options_end(struct parse_opt_ctx_t *ctx) @@ -585,6 +586,7 @@ int parse_options(int argc, const char **argv, const char *prefix, parse_options_start(&ctx, argc, argv, prefix, options, flags); switch (parse_options_step(&ctx, options, usagestr)) { case PARSE_OPT_HELP: + case PARSE_OPT_ERROR: exit(129); case PARSE_OPT_NON_OPTION: case PARSE_OPT_DONE: |