Skip to content

Commit ff962a3

Browse files
MadCodergitster
authored andcommitted
parse-opt: bring PARSE_OPT_HIDDEN and NONEG to git-rev-parse --parseopt
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c149184 commit ff962a3

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

Documentation/git-rev-parse.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ The lines after the separator describe the options.
325325
Each line of options has this format:
326326

327327
------------
328-
<opt_spec><arg_spec>? SP+ help LF
328+
<opt_spec><flags>* SP+ help LF
329329
------------
330330

331331
`<opt_spec>`::
@@ -334,10 +334,17 @@ Each line of options has this format:
334334
is necessary. `h,help`, `dry-run` and `f` are all three correct
335335
`<opt_spec>`.
336336

337-
`<arg_spec>`::
338-
an `<arg_spec>` tells the option parser if the option has an argument
339-
(`=`), an optional one (`?` though its use is discouraged) or none
340-
(no `<arg_spec>` in that case).
337+
`<flags>`::
338+
`<flags>` are of `*`, `=`, `?` or `!`.
339+
* Use `=` if the option takes an argument.
340+
341+
* Use `?` to mean that the option is optional (though its use is discouraged).
342+
343+
* Use `*` to mean that this option should not be listed in the usage
344+
generated for the `-h` argument. It's shown for `--help-all` as
345+
documented in linkgit:gitcli[5].
346+
347+
* Use `!` to not make the corresponding negated long option available.
341348

342349
The remainder of the line, after stripping the spaces, is used
343350
as the help associated to the option.

builtin-rev-parse.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,24 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
322322
o->type = OPTION_CALLBACK;
323323
o->help = xstrdup(skipspaces(s));
324324
o->value = &parsed;
325+
o->flags = PARSE_OPT_NOARG;
325326
o->callback = &parseopt_dump;
326-
switch (s[-1]) {
327-
case '=':
328-
s--;
329-
break;
330-
case '?':
331-
o->flags = PARSE_OPT_OPTARG;
332-
s--;
333-
break;
334-
default:
335-
o->flags = PARSE_OPT_NOARG;
336-
break;
327+
while (s > sb.buf && strchr("*=?!", s[-1])) {
328+
switch (*--s) {
329+
case '=':
330+
o->flags &= ~PARSE_OPT_NOARG;
331+
break;
332+
case '?':
333+
o->flags &= ~PARSE_OPT_NOARG;
334+
o->flags |= PARSE_OPT_OPTARG;
335+
break;
336+
case '!':
337+
o->flags |= PARSE_OPT_NONEG;
338+
break;
339+
case '*':
340+
o->flags |= PARSE_OPT_HIDDEN;
341+
break;
342+
}
337343
}
338344

339345
if (s - sb.buf == 1) /* short option only */

0 commit comments

Comments
 (0)