parse-opt: bring PARSE_OPT_HIDDEN and NONEG to git-rev-parse --parseopt
authorPierre Habouzit <madcoder@debian.org>
Sun, 2 Mar 2008 08:21:38 +0000 (09:21 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Mar 2008 22:07:47 +0000 (14:07 -0800)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-rev-parse.txt
builtin-rev-parse.c
index f02f6bbb49182c0dffce205b24a4199d824dc776..6513c2efe17668d5fc25a21385ed117ec76b40b5 100644 (file)
@@ -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:
        is necessary. `h,help`, `dry-run` and `f` are all three correct
        `<opt_spec>`.
 
        is necessary. `h,help`, `dry-run` and `f` are all three correct
        `<opt_spec>`.
 
-`<arg_spec>`::
-       an `<arg_spec>` tells the option parser if the option has an argument
-       (`=`), an optional one (`?` though its use is discouraged) or none
-       (no `<arg_spec>` in that case).
+`<flags>`::
+       `<flags>` are of `*`, `=`, `?` or `!`.
+       * Use `=` if the option takes an argument.
+
+       * 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
 as the help associated to the option.
 
 The remainder of the line, after stripping the spaces, is used
 as the help associated to the option.
index 90dbb9d7c1a28fd463ba827cb8da2eab42e489df..0351d54435b566d5030f3a83df57fb140fffc143 100644 (file)
@@ -322,18 +322,24 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
                o->type = OPTION_CALLBACK;
                o->help = xstrdup(skipspaces(s));
                o->value = &parsed;
                o->type = OPTION_CALLBACK;
                o->help = xstrdup(skipspaces(s));
                o->value = &parsed;
+               o->flags = PARSE_OPT_NOARG;
                o->callback = &parseopt_dump;
                o->callback = &parseopt_dump;
-               switch (s[-1]) {
-               case '=':
-                       s--;
-                       break;
-               case '?':
-                       o->flags = PARSE_OPT_OPTARG;
-                       s--;
-                       break;
-               default:
-                       o->flags = PARSE_OPT_NOARG;
-                       break;
+               while (s > sb.buf && strchr("*=?!", s[-1])) {
+                       switch (*--s) {
+                       case '=':
+                               o->flags &= ~PARSE_OPT_NOARG;
+                               break;
+                       case '?':
+                               o->flags &= ~PARSE_OPT_NOARG;
+                               o->flags |= PARSE_OPT_OPTARG;
+                               break;
+                       case '!':
+                               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 */