Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2023-08-05 17:44:45 +0300
committerJunio C Hamano <gitster@pobox.com>2023-08-07 03:16:51 +0300
commit2a409a1d1250c8a9fcac7beaa58ae80881dda2dc (patch)
treea01a8f2e2bdb13daf66b69c0fb97cc345864f200 /parse-options.c
parent652a6b15bc1cd0f837bc969e87fd31f3e88413f6 (diff)
parse-options: no --[no-]no-...
Avoid showing an optional "no-" for options that already start with a "no-" in the short help, as that double negation is confusing. Document the opposite variant on its own line with a generated help text instead, unless it's defined and documented explicitly already. 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.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/parse-options.c b/parse-options.c
index 4b76fc81e9..4a8d380ceb 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1042,11 +1042,22 @@ static void usage_padding(FILE *outfile, size_t pos)
fprintf(outfile, "%*s", pad + USAGE_GAP, "");
}
+static const struct option *find_option_by_long_name(const struct option *opts,
+ const char *long_name)
+{
+ for (; opts->type != OPTION_END; opts++) {
+ if (opts->long_name && !strcmp(opts->long_name, long_name))
+ return opts;
+ }
+ return NULL;
+}
+
static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *ctx,
const char * const *usagestr,
const struct option *opts,
int full, int err)
{
+ const struct option *all_opts = opts;
FILE *outfile = err ? stderr : stdout;
int need_newline;
@@ -1128,6 +1139,7 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
for (; opts->type != OPTION_END; opts++) {
size_t pos;
const char *cp, *np;
+ const char *positive_name = NULL;
if (opts->type == OPTION_SUBCOMMAND)
continue;
@@ -1157,7 +1169,8 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
pos += fprintf(outfile, ", ");
if (opts->long_name) {
const char *long_name = opts->long_name;
- if (opts->flags & PARSE_OPT_NONEG)
+ if ((opts->flags & PARSE_OPT_NONEG) ||
+ skip_prefix(long_name, "no-", &positive_name))
pos += fprintf(outfile, "--%s", long_name);
else
pos += fprintf(outfile, "--[no-]%s", long_name);
@@ -1185,6 +1198,16 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
np++;
pos = 0;
}
+
+ if (positive_name) {
+ if (find_option_by_long_name(all_opts, positive_name))
+ continue;
+ pos = usage_indent(outfile);
+ pos += fprintf(outfile, "--%s", positive_name);
+ usage_padding(outfile, pos);
+ fprintf_ln(outfile, _("opposite of --no-%s"),
+ positive_name);
+ }
}
fputc('\n', outfile);