Skip to content

Commit e3a0ca8

Browse files
bebarinogitster
authored andcommitted
parse-options: make OPT_INTEGER's argh explicit
OPTION_INTEGER hardcodes its argh member to be "n", but the decision is hidden deep in usage_with_options_internal(). Make "n" the default argh for the OPT_INTEGER macro while leaving it undecided for the OPTION_INTEGER enum. This makes it less surprising to users that argh is "n" when using the OPT_INTEGER macro. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Reviewed-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6096d75 commit e3a0ca8

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

builtin-tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
376376
struct commit_list *with_commit = NULL;
377377
struct option options[] = {
378378
OPT_BOOLEAN('l', NULL, &list, "list tag names"),
379-
{ OPTION_INTEGER, 'n', NULL, &lines, NULL,
380-
"print n lines of each tag message",
379+
{ OPTION_INTEGER, 'n', NULL, &lines, "n",
380+
"print <n> lines of each tag message",
381381
PARSE_OPT_OPTARG, NULL, 1 },
382382
OPT_BOOLEAN('d', NULL, &delete, "delete tags"),
383383
OPT_BOOLEAN('v', NULL, &verify, "verify tags"),

parse-options.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,19 +503,12 @@ int usage_with_options_internal(const char * const *usagestr,
503503
switch (opts->type) {
504504
case OPTION_ARGUMENT:
505505
break;
506-
case OPTION_INTEGER:
507-
if (opts->flags & PARSE_OPT_OPTARG)
508-
if (opts->long_name)
509-
pos += fprintf(stderr, "[=<n>]");
510-
else
511-
pos += fprintf(stderr, "[<n>]");
512-
else
513-
pos += fprintf(stderr, " <n>");
514-
break;
515506
case OPTION_CALLBACK:
516507
if (opts->flags & PARSE_OPT_NOARG)
517508
break;
518509
/* FALLTHROUGH */
510+
case OPTION_INTEGER:
511+
/* FALLTHROUGH */
519512
case OPTION_FILENAME:
520513
/* FALLTHROUGH */
521514
case OPTION_STRING:

parse-options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct option {
108108
#define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) }
109109
#define OPT_SET_INT(s, l, v, h, i) { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) }
110110
#define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }
111-
#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), NULL, (h) }
111+
#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), "n", (h) }
112112
#define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) }
113113
#define OPT_DATE(s, l, v, h) \
114114
{ OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \

0 commit comments

Comments
 (0)