From: Pierre Habouzit <madcoder@debian.org>
To: Junio C Hamano <gitster@pobox.com>,
Yann Dirson <ydirson@altern.org>,
git@vger.kernel.org
Subject: [PATCH] parse-opt: bring PARSE_OPT_HIDDEN to git-rev-parse --parseopt
Date: Sat, 23 Feb 2008 15:09:26 +0100 [thread overview]
Message-ID: <20080223140926.GD10967@artemis.madism.org> (raw)
In-Reply-To: <20080222181927.GA4555@artemis.madism.org>
[-- Attachment #1: Type: text/plain, Size: 3053 bytes --]
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
On ven, fév 22, 2008 at 06:19:28 +0000, Pierre Habouzit wrote:
> On Fri, Feb 22, 2008 at 05:17:51PM +0000, Junio C Hamano wrote:
> > I did not find accessible from the command line variant was the
> > parse-opt-hidden feature, which was frustrating.
>
> Well, it's probably doable using some more magic flags, I can hack
> something if you need to, I'll try to work something out during FOSDEM's
> talks :)
Here it is …
I also made the parsing more extensible wrt new flags if needed.
We should definitely write tests too.
Documentation/git-rev-parse.txt | 15 ++++++++++-----
builtin-rev-parse.c | 25 ++++++++++++++-----------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index f02f6bb..e961c20 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:
------------
-<opt_spec><arg_spec>? SP+ help LF
+<opt_spec><flags>? SP+ help LF
------------
`<opt_spec>`::
@@ -334,10 +334,15 @@ Each line of options has this format:
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 any suite of `*`, `=` or `?`.
+ * Use `=` if the option take 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].
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 b9af1a5..5ffc4e0 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -322,18 +322,21 @@ 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_HIDDEN;
+ break;
+ }
}
if (s - sb.buf == 1) /* short option only */
--
1.5.4.2.281.g28d0e
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2008-02-23 14:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-21 23:01 [PATCH] Improve documentation for git-sh-setup Yann Dirson
2008-02-22 9:35 ` Pierre Habouzit
2008-02-22 17:17 ` Junio C Hamano
2008-02-22 18:19 ` Pierre Habouzit
2008-02-23 14:09 ` Pierre Habouzit [this message]
2008-02-24 8:42 ` [PATCH] parse-opt: bring PARSE_OPT_HIDDEN to git-rev-parse --parseopt Junio C Hamano
2008-02-24 8:49 ` Pierre Habouzit
-- strict thread matches above, loose matches on Subject: below --
2008-03-02 8:21 Pierre Habouzit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080223140926.GD10967@artemis.madism.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ydirson@altern.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.