parse-options: teach "git cmd -h" to show alias as alias
There is a long-standing NEEDSWORK comment that complains about inconsistency between how an aliased option ("git clone --recurse" which is the only one that currently exists) gives a help text in a usage-error message vs "git cmd -h"). Get rid of it and then make sure we say an option is an alias for another, instead of repeating the same short help text for both, which leads to "they seem to do the same---is there any subtle difference?" puzzlement to end-users. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 16, 2020 at 13:22 UTC
7c280589cffa6f55f6bef0496776334f1e3cdcb5
2 files changed
+4
-7
parse-options.c
+3
-6
@@ -648,6 +648,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
648
int short_name;
649
const char *long_name;
650
const char *source;
651
+ struct strbuf help = STRBUF_INIT;
652
int j;
653
654
if (newopt[i].type != OPTION_ALIAS)
@@ -659,6 +660,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
660
661
if (!long_name)
662
BUG("An alias must have long option name");
663
+ strbuf_addf(&help, _("alias of --%s"), source);
664
665
for (j = 0; j < nr; j++) {
666
const char *name = options[j].long_name;
@@ -669,15 +671,10 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
671
if (options[j].type == OPTION_ALIAS)
672
BUG("No please. Nested aliases are not supported.");
673
672
- /*
673
- * NEEDSWORK: this is a bit inconsistent because
674
- * usage_with_options() on the original options[] will print
675
- * help string as "alias of %s" but "git cmd -h" will
676
- * print the original help string.
677
- */
674
memcpy(newopt + i, options + j, sizeof(*newopt));
675
newopt[i].short_name = short_name;
676
newopt[i].long_name = long_name;
677
+ newopt[i].help = strbuf_detach(&help, NULL);
678
break;
679
}
680
t/t0040-parse-options.sh
+1
-1
@@ -54,7 +54,7 @@ Alias
54
-A, --alias-source <string>
55
get a string
56
-Z, --alias-target <string>
57
- get a string
57
+ alias of --alias-source
58
59
EOF
60