diff options
author | René Scharfe <l.s.r@web.de> | 2023-08-05 17:40:59 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-08-07 03:16:50 +0300 |
commit | e8e5d294dc6e3b6b32132cc8018d01ce35ad0af0 (patch) | |
tree | 0322d505e3563a0a775822be930b66d26ccc8c8c /parse-options.c | |
parent | d5dc68f73041f95c1179fb092005e2326bdd8a7b (diff) |
parse-options: show negatability of options in short help
Add a "[no-]" prefix to options without the flag PARSE_OPT_NONEG to
document the fact that you can negate them.
This looks a bit strange for options that already start with "no-", e.g.
for the option --no-name of git show-branch:
--[no-]no-name suppress naming strings
You can actually use --no-no-name as an alias of --name, so the short
help is not wrong. If we strip off any of the "no-"s, we lose either
the ability to see if the remaining one belongs to the documented
variant or to see if it can be negated.
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r-- | parse-options.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/parse-options.c b/parse-options.c index 87c9fae634..b750bf91cd 100644 --- a/parse-options.c +++ b/parse-options.c @@ -1137,8 +1137,14 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t } if (opts->long_name && opts->short_name) pos += fprintf(outfile, ", "); - if (opts->long_name) - pos += fprintf(outfile, "--%s", opts->long_name); + if (opts->long_name) { + const char *long_name = opts->long_name; + if (opts->flags & PARSE_OPT_NONEG) + pos += fprintf(outfile, "--%s", long_name); + else + pos += fprintf(outfile, "--[no-]%s", long_name); + } + if (opts->type == OPTION_NUMBER) pos += utf8_fprintf(outfile, _("-NUM")); |