Skip to content

Commit 397091d

Browse files
benknoblegitster
authored andcommitted
parse-options: refactor flags for usage_with_options_internal
When reading or editing calls to usage_with_options_internal, it is difficult to tell what trailing "0, 0", "0, 1", "1, 0" arguments mean (NB there is never a "1, 1" case). Give the flags readable names to improve call-sites without changing any behavior. Signed-off-by: D. Ben Knoble <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72561e3 commit 397091d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

parse-options.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,16 @@ static void free_preprocessed_options(struct option *options)
953953
free(options);
954954
}
955955

956+
#define USAGE_NORMAL 0
957+
#define USAGE_FULL 1
958+
#define USAGE_TO_STDOUT 0
959+
#define USAGE_TO_STDERR 1
960+
956961
static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *,
957962
const char * const *,
958963
const struct option *,
959-
int, int);
964+
int full_usage,
965+
int usage_to_stderr);
960966

961967
enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
962968
const struct option *options,
@@ -1088,7 +1094,8 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
10881094
}
10891095

10901096
if (internal_help && !strcmp(arg + 2, "help-all"))
1091-
return usage_with_options_internal(ctx, usagestr, options, 1, 0);
1097+
return usage_with_options_internal(ctx, usagestr, options,
1098+
USAGE_FULL, USAGE_TO_STDOUT);
10921099
if (internal_help && !strcmp(arg + 2, "help"))
10931100
goto show_usage;
10941101
switch (parse_long_opt(ctx, arg + 2, options)) {
@@ -1129,7 +1136,8 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
11291136
return PARSE_OPT_DONE;
11301137

11311138
show_usage:
1132-
return usage_with_options_internal(ctx, usagestr, options, 0, 0);
1139+
return usage_with_options_internal(ctx, usagestr, options,
1140+
USAGE_NORMAL, USAGE_TO_STDOUT);
11331141
}
11341142

11351143
int parse_options_end(struct parse_opt_ctx_t *ctx)
@@ -1444,7 +1452,8 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
14441452
void NORETURN usage_with_options(const char * const *usagestr,
14451453
const struct option *opts)
14461454
{
1447-
usage_with_options_internal(NULL, usagestr, opts, 0, 1);
1455+
usage_with_options_internal(NULL, usagestr, opts,
1456+
USAGE_NORMAL, USAGE_TO_STDERR);
14481457
exit(129);
14491458
}
14501459

@@ -1453,7 +1462,8 @@ void show_usage_with_options_if_asked(int ac, const char **av,
14531462
const struct option *opts)
14541463
{
14551464
if (ac == 2 && !strcmp(av[1], "-h")) {
1456-
usage_with_options_internal(NULL, usagestr, opts, 0, 0);
1465+
usage_with_options_internal(NULL, usagestr, opts,
1466+
USAGE_NORMAL, USAGE_TO_STDOUT);
14571467
exit(129);
14581468
}
14591469
}

0 commit comments

Comments
 (0)