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>
Pierre Habouzit committed
Mar 2, 2008 at 09:21 UTC
ff962a3f1900966d008d6f9eaf32095c42322b9d
2 files changed
+29
-16
Documentation/git-rev-parse.txt
+12
-5
@@ -325,7 +325,7 @@ The lines after the separator describe the options.
325
Each line of options has this format:
326
327
------------
328
-<opt_spec><arg_spec>? SP+ help LF
328
+<opt_spec><flags>* SP+ help LF
329
------------
330
331
`<opt_spec>`::
@@ -334,10 +334,17 @@ Each line of options has this format:
334
is necessary. `h,help`, `dry-run` and `f` are all three correct
335
`<opt_spec>`.
336
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.
348
349
The remainder of the line, after stripping the spaces, is used
350
as the help associated to the option.
builtin-rev-parse.c
+17
-11
@@ -322,18 +322,24 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
322
o->type = OPTION_CALLBACK;
323
o->help = xstrdup(skipspaces(s));
324
o->value = &parsed;
325
+ o->flags = PARSE_OPT_NOARG;
326
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
+ }
343
}
344
345
if (s - sb.buf == 1) /* short option only */