Skip to content

Commit

Permalink
parse-options: teach "git cmd -h" to show alias as alias
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gitster committed Mar 16, 2020
1 parent 6c85aac commit 7c28058
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
int short_name;
const char *long_name;
const char *source;
struct strbuf help = STRBUF_INIT;
int j;

if (newopt[i].type != OPTION_ALIAS)
Expand All @@ -659,6 +660,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,

if (!long_name)
BUG("An alias must have long option name");
strbuf_addf(&help, _("alias of --%s"), source);

for (j = 0; j < nr; j++) {
const char *name = options[j].long_name;
Expand All @@ -669,15 +671,10 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
if (options[j].type == OPTION_ALIAS)
BUG("No please. Nested aliases are not supported.");

/*
* NEEDSWORK: this is a bit inconsistent because
* usage_with_options() on the original options[] will print
* help string as "alias of %s" but "git cmd -h" will
* print the original help string.
*/
memcpy(newopt + i, options + j, sizeof(*newopt));
newopt[i].short_name = short_name;
newopt[i].long_name = long_name;
newopt[i].help = strbuf_detach(&help, NULL);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion t/t0040-parse-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Alias
-A, --alias-source <string>
get a string
-Z, --alias-target <string>
get a string
alias of --alias-source
EOF

Expand Down

0 comments on commit 7c28058

Please sign in to comment.