提交 ff962a3f 编写于 作者: P Pierre Habouzit 提交者: Junio C Hamano

parse-opt: bring PARSE_OPT_HIDDEN and NONEG to git-rev-parse --parseopt

Signed-off-by: NPierre Habouzit <madcoder@debian.org>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 c1491841
...@@ -325,7 +325,7 @@ The lines after the separator describe the options. ...@@ -325,7 +325,7 @@ The lines after the separator describe the options.
Each line of options has this format: Each line of options has this format:
------------ ------------
<opt_spec><arg_spec>? SP+ help LF <opt_spec><flags>* SP+ help LF
------------ ------------
`<opt_spec>`:: `<opt_spec>`::
...@@ -334,10 +334,17 @@ Each line of options has this format: ...@@ -334,10 +334,17 @@ Each line of options has this format:
is necessary. `h,help`, `dry-run` and `f` are all three correct is necessary. `h,help`, `dry-run` and `f` are all three correct
`<opt_spec>`. `<opt_spec>`.
`<arg_spec>`:: `<flags>`::
an `<arg_spec>` tells the option parser if the option has an argument `<flags>` are of `*`, `=`, `?` or `!`.
(`=`), an optional one (`?` though its use is discouraged) or none * Use `=` if the option takes an argument.
(no `<arg_spec>` in that case).
* Use `?` to mean that the option is optional (though its use is discouraged).
* Use `*` to mean that this option should not be listed in the usage
generated for the `-h` argument. It's shown for `--help-all` as
documented in linkgit:gitcli[5].
* Use `!` to not make the corresponding negated long option available.
The remainder of the line, after stripping the spaces, is used The remainder of the line, after stripping the spaces, is used
as the help associated to the option. as the help associated to the option.
......
...@@ -322,18 +322,24 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) ...@@ -322,18 +322,24 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
o->type = OPTION_CALLBACK; o->type = OPTION_CALLBACK;
o->help = xstrdup(skipspaces(s)); o->help = xstrdup(skipspaces(s));
o->value = &parsed; o->value = &parsed;
o->flags = PARSE_OPT_NOARG;
o->callback = &parseopt_dump; o->callback = &parseopt_dump;
switch (s[-1]) { while (s > sb.buf && strchr("*=?!", s[-1])) {
case '=': switch (*--s) {
s--; case '=':
break; o->flags &= ~PARSE_OPT_NOARG;
case '?': break;
o->flags = PARSE_OPT_OPTARG; case '?':
s--; o->flags &= ~PARSE_OPT_NOARG;
break; o->flags |= PARSE_OPT_OPTARG;
default: break;
o->flags = PARSE_OPT_NOARG; case '!':
break; o->flags |= PARSE_OPT_NONEG;
break;
case '*':
o->flags |= PARSE_OPT_HIDDEN;
break;
}
} }
if (s - sb.buf == 1) /* short option only */ if (s - sb.buf == 1) /* short option only */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册