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;
fprintf(outfile, "%s\n", _(opts->help));
continue;
}
- if (!full && (opts->flags & PARSE_OPT_HIDDEN))
- continue;
if (need_newline) {
fputc('\n', outfile);
.type = OPTION_GROUP, \
.help = (h), \
}
+#define OPT_HIDDEN_GROUP(h) { \
+ .type = OPTION_GROUP, \
+ .help = (h), \
+ .flags = PARSE_OPT_HIDDEN, \
+}
#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
#define OPT_BITOP(s, l, v, h, set, clear) { \
.type = OPTION_BITOP, \
OPT_GROUP("Alias"),
OPT_STRING('A', "alias-source", &string, "string", "get a string"),
OPT_ALIAS('Z', "alias-target", "alias-source"),
+ OPT_HIDDEN_GROUP("Hidden options"),
+ OPT_HIDDEN_BOOL(0, "hidden-bool", &boolean, "get a boolean"),
+ OPT_INTEGER_F('k', "hidden-integer", &integer, "get a integer",
+ PARSE_OPT_HIDDEN),
OPT_END(),
};
int ret = 0;
. ./test-lib.sh
-cat >expect <<\EOF
+cat >expect-part1 <<\EOF
usage: test-tool parse-options <options>
A helper function for the parse-options API.
--[no-]string2 <str> get another string
--[no-]st <st> get another string (pervert ordering)
-o <str> get another string
+EOF
+
+cat >expect-part2 <<\EOF
--longhelp help text of this entry
spans multiple lines
--[no-]list <str> add str to list
EOF
+cat >expect-noop <<\EOF
+ --[no-]obsolete no-op (backward compatibility)
+EOF
+
+cat >expect-hidden <<\EOF
+Hidden options
+ --[no-]hidden-bool get a boolean
+ -k, --[no-]hidden-integer <n>
+ get a integer
+
+EOF
+
test_expect_success 'test help' '
+ cat expect-part1 expect-part2 >expect &&
test_must_fail test-tool parse-options -h >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
'
+test_expect_success 'test --help-all shows hidden group and options' '
+ cat expect-part1 expect-noop expect-part2 expect-hidden >expect-help-all &&
+ test_must_fail test-tool parse-options --help-all >output 2>output.err &&
+ test_must_be_empty output.err &&
+ test_cmp expect-help-all output
+'
+
mv expect expect.err
check () {