From: Michele Ballabio <barra_cuda@katamail.com>
To: git@vger.kernel.org
Cc: Stephan Beyer <s-beyer@gmx.net>,
Pierre Habouzit <madcoder@debian.org>,
Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] parse-options.c: fix documentation syntax of optional arguments
Date: Sun, 22 Jun 2008 16:39:04 +0200 [thread overview]
Message-ID: <200806221639.04811.barra_cuda@katamail.com> (raw)
In-Reply-To: <20080622134550.GA5279@leksak.fem-net>
When an argument for an option is optional, short options don't need a
space between the option and the argument, and long options need a "=".
Otherwise, arguments are misinterpreted.
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
On Sunday 22 June 2008, Stephan Beyer wrote:
> > > +`OPT__ABBREV(&int_var)`::
> > > + Add `\--abbrev [<n>]`.
> >
> > better:
> > + Add `\--abbrev[=<n>]`.
> >
> > since the <n> is optional.
>
> That's right and I also expected that print_usage_with_options() would
> do so, since the other variant is ambiguous, BUT:
>
> $ ./test-parse-options -h 2>&1 | grep abbrev
> --abbrev [<n>] use <n> digits to display SHA-1s
>
> And I didn't want to change parse-options.c ;-)
Here it is.
parse-options.c | 15 ++++++++++++---
t/t1502-rev-parse-parseopt.sh | 2 +-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index acf3fe3..f8d52e2 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -344,7 +344,10 @@ void usage_with_options_internal(const char * const *usagestr,
break;
case OPTION_INTEGER:
if (opts->flags & PARSE_OPT_OPTARG)
- pos += fprintf(stderr, "[<n>]");
+ if (opts->long_name)
+ pos += fprintf(stderr, "[=<n>]");
+ else
+ pos += fprintf(stderr, "[<n>]");
else
pos += fprintf(stderr, " <n>");
break;
@@ -355,12 +358,18 @@ void usage_with_options_internal(const char * const *usagestr,
case OPTION_STRING:
if (opts->argh) {
if (opts->flags & PARSE_OPT_OPTARG)
- pos += fprintf(stderr, " [<%s>]", opts->argh);
+ if (opts->long_name)
+ pos += fprintf(stderr, "[=<%s>]", opts->argh);
+ else
+ pos += fprintf(stderr, "[<%s>]", opts->argh);
else
pos += fprintf(stderr, " <%s>", opts->argh);
} else {
if (opts->flags & PARSE_OPT_OPTARG)
- pos += fprintf(stderr, " [...]");
+ if (opts->long_name)
+ pos += fprintf(stderr, "[=...]");
+ else
+ pos += fprintf(stderr, "[...]");
else
pos += fprintf(stderr, " ...");
}
diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh
index d24a47d..3508d0a 100755
--- a/t/t1502-rev-parse-parseopt.sh
+++ b/t/t1502-rev-parse-parseopt.sh
@@ -13,7 +13,7 @@ usage: some-command [options] <args>...
--bar ... some cool option --bar with an argument
An option group Header
- -C [...] option C with an optional argument
+ -C[...] option C with an optional argument
Extras
--extra1 line above used to cause a segfault but no longer does
--
1.5.6
next prev parent reply other threads:[~2008-06-22 14:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-22 0:00 [PATCH 1/2] api-parse-options.txt: Introduce documentation for parse options API Stephan Beyer
2008-06-22 0:00 ` [PATCH 2/2] Extend parse-options test suite Stephan Beyer
2008-06-22 12:49 ` [PATCH 1/2] api-parse-options.txt: Introduce documentation for parse options API Michele Ballabio
2008-06-22 13:45 ` Stephan Beyer
2008-06-22 14:39 ` Michele Ballabio [this message]
2008-06-22 15:04 ` [PATCH v2 " Stephan Beyer
2008-06-22 15:04 ` [PATCH v2 2/2] Extend parse-options test suite Stephan Beyer
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=200806221639.04811.barra_cuda@katamail.com \
--to=barra_cuda@katamail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=madcoder@debian.org \
--cc=s-beyer@gmx.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).