mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
parse-options: deduplicate parse_options_usage() calls
Avoid long lines and repeating parse_options_usage() calls with their duplicate parameters by providing labels with speaking names to jump to. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:
parent
0c83680e9c
commit
ac20ff6daa
|
@ -435,6 +435,7 @@ 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;
|
||||
|
@ -454,10 +455,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
|
|||
if (arg[1] != '-') {
|
||||
ctx->opt = arg + 1;
|
||||
if (internal_help && *ctx->opt == 'h')
|
||||
return parse_options_usage(ctx, usagestr, options, 0);
|
||||
goto show_usage;
|
||||
switch (parse_short_opt(ctx, options)) {
|
||||
case -1:
|
||||
return parse_options_usage(ctx, usagestr, options, 1);
|
||||
goto show_usage_error;
|
||||
case -2:
|
||||
if (ctx->opt)
|
||||
check_typos(arg + 1, options);
|
||||
|
@ -467,10 +468,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
|
|||
check_typos(arg + 1, options);
|
||||
while (ctx->opt) {
|
||||
if (internal_help && *ctx->opt == 'h')
|
||||
return parse_options_usage(ctx, usagestr, options, 0);
|
||||
goto show_usage;
|
||||
switch (parse_short_opt(ctx, options)) {
|
||||
case -1:
|
||||
return parse_options_usage(ctx, usagestr, options, 1);
|
||||
goto show_usage_error;
|
||||
case -2:
|
||||
/* fake a short option thing to hide the fact that we may have
|
||||
* started to parse aggregated stuff
|
||||
|
@ -496,10 +497,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
|
|||
if (internal_help && !strcmp(arg + 2, "help-all"))
|
||||
return usage_with_options_internal(ctx, usagestr, options, 1, 0);
|
||||
if (internal_help && !strcmp(arg + 2, "help"))
|
||||
return parse_options_usage(ctx, usagestr, options, 0);
|
||||
goto show_usage;
|
||||
switch (parse_long_opt(ctx, arg + 2, options)) {
|
||||
case -1:
|
||||
return parse_options_usage(ctx, usagestr, options, 1);
|
||||
goto show_usage_error;
|
||||
case -2:
|
||||
goto unknown;
|
||||
}
|
||||
|
@ -511,6 +512,11 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
|
|||
ctx->opt = NULL;
|
||||
}
|
||||
return PARSE_OPT_DONE;
|
||||
|
||||
show_usage_error:
|
||||
err = 1;
|
||||
show_usage:
|
||||
return parse_options_usage(ctx, usagestr, options, err);
|
||||
}
|
||||
|
||||
int parse_options_end(struct parse_opt_ctx_t *ctx)
|
||||
|
|
Loading…
Reference in a new issue