From ff962a3f1900966d008d6f9eaf32095c42322b9d Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 2 Mar 2008 09:21:38 +0100 Subject: [PATCH] parse-opt: bring PARSE_OPT_HIDDEN and NONEG to git-rev-parse --parseopt Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- Documentation/git-rev-parse.txt | 17 ++++++++++++----- builtin-rev-parse.c | 28 +++++++++++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index f02f6bbb4..6513c2efe 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -325,7 +325,7 @@ The lines after the separator describe the options. Each line of options has this format: ------------ -? SP+ help LF +* SP+ help LF ------------ ``:: @@ -334,10 +334,17 @@ Each line of options has this format: is necessary. `h,help`, `dry-run` and `f` are all three correct ``. -``:: - an `` tells the option parser if the option has an argument - (`=`), an optional one (`?` though its use is discouraged) or none - (no `` in that case). +``:: + `` 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. diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c index 90dbb9d7c..0351d5443 100644 --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@ -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->flags = PARSE_OPT_NOARG; 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 */ -- 2.30.2