@@ -110,7 +110,7 @@ static struct option builtin_clone_options[] = {
{ OPTION_CALLBACK, 0, "recurse-submodules", &option_recurse_submodules,
N_("pathspec"), N_("initialize submodules in the clone"),
PARSE_OPT_OPTARG, recurse_submodules_cb, (intptr_t)"." },
- OPT_ALIAS(0, "recursive", "recurse-submodules"),
+ OPT_HIDDEN_ALIAS(0, "recursive", "recurse-submodules"),
OPT_INTEGER('j', "jobs", &max_jobs,
N_("number of submodules cloned in parallel")),
OPT_STRING(0, "template", &option_template, N_("template-directory"),
@@ -653,6 +653,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
int short_name;
const char *long_name;
const char *source;
+ int flags;
struct strbuf help = STRBUF_INIT;
int j;
@@ -662,6 +663,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
short_name = newopt[i].short_name;
long_name = newopt[i].long_name;
source = newopt[i].value;
+ flags = newopt[i].flags;
if (!long_name)
BUG("An alias must have long option name");
@@ -680,7 +682,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
newopt[i].short_name = short_name;
newopt[i].long_name = long_name;
newopt[i].help = strbuf_detach(&help, NULL);
- newopt[i].flags |= PARSE_OPT_FROM_ALIAS;
+ newopt[i].flags |= PARSE_OPT_FROM_ALIAS | flags;
break;
}
@@ -201,6 +201,9 @@ struct option {
#define OPT_ALIAS(s, l, source_long_name) \
{ OPTION_ALIAS, (s), (l), (source_long_name) }
+#define OPT_HIDDEN_ALIAS(s, l, source_long_name) \
+ { OPTION_ALIAS, (s), (l), (source_long_name), NULL, NULL, PARSE_OPT_HIDDEN }
+
/*
* parse_options() will filter out the processed options and leave the
* non-option arguments in argv[]. argv0 is assumed program name and
@@ -154,6 +154,7 @@ int cmd__parse_options(int argc, const char **argv)
OPT_GROUP("Alias"),
OPT_STRING('A', "alias-source", &string, "string", "get a string"),
OPT_ALIAS('Z', "alias-target", "alias-source"),
+ OPT_HIDDEN_ALIAS(0, "hidden-alias", "alias-source"),
OPT_END(),
};
int i;
@@ -7,7 +7,7 @@ test_description='our own option parser'
. ./test-lib.sh
-cat >expect <<\EOF
+cat >help-all.in <<\EOF
usage: test-tool parse-options <options>
A helper function for the parse-options API.
@@ -34,6 +34,7 @@ String options
--string2 <str> get another string
--st <st> get another string (pervert ordering)
-o <str> get another string
+# --obsolete no-op (backward compatibility)
--list <str> add str to list
Magic arguments
@@ -55,10 +56,20 @@ Alias
get a string
-Z, --alias-target <string>
alias of --alias-source
+# --hidden-alias <string>
+# alias of --alias-source
EOF
+test_expect_success 'hidden alias in test help' '
+ sed -e "s/^#//" help-all.in >expect &&
+ test_must_fail test-tool parse-options --help-all >output 2>output.err &&
+ test_must_be_empty output.err &&
+ test_cmp expect output
+'
+
test_expect_success 'test help' '
+ sed -e "/^#/d" help-all.in >expect &&
test_must_fail test-tool parse-options -h >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output