parse-options: introduce OPT_HIDDEN_GROUP

Hidden options are not shown by `git <cmd> -h`, but are still shown by
`git <cmd> --help-all`. If there are a lot of hidden options or if they
don't belong to the same categories as other options, there is
currently no way to properly group them.

Using `OPT_GROUP("Foo")` means that "Foo" will always be shown which we
don't want if that group contains only hidden options.

To provide a way to have groups shown only when hidden options are
shown, let's implement an OPT_HIDDEN_GROUP macro.

To test this new macro, let's also improve `test-tool parse-options`
and test its output with `--help-all`.

Signed-off-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder
2026-08-04 12:03:44 +02:00
committed by Junio C Hamano
parent 5b2471720c
commit 52a6786aba
4 changed files with 35 additions and 3 deletions

View File

@@ -1414,6 +1414,8 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
if (opts->type == OPTION_SUBCOMMAND)
continue;
if (!full && (opts->flags & PARSE_OPT_HIDDEN))
continue;
if (opts->type == OPTION_GROUP) {
fputc('\n', outfile);
need_newline = 0;
@@ -1421,8 +1423,6 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
fprintf(outfile, "%s\n", _(opts->help));
continue;
}
if (!full && (opts->flags & PARSE_OPT_HIDDEN))
continue;
if (need_newline) {
fputc('\n', outfile);