From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Stephen Boyd <bebarino@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] parse-options: make OPT_NUMBER's argh explicit
Date: Wed, 03 Jun 2009 12:18:34 +0200 [thread overview]
Message-ID: <4A264DFA.3090309@lsrfire.ath.cx> (raw)
In-Reply-To: <1244015367-16998-1-git-send-email-bebarino@gmail.com>
Stephen Boyd schrieb:
> OPTION_NUMBER hard codes its argh member to be "n", but the decision is
> hidden deep in usage_with_options_internal(). Make "n" the default argh
> for the OPT_NUMBER macro while leaving it undecided for the OPTION_NUMBER
> enum.
>
> This make it less surprising to users that argh is "n" when using the
> OPT_NUMBER macro.
>
> Signed-off-by: Stephen Boyd <bebarino@gmail.com>
> ---
> builtin-tag.c | 4 ++--
> parse-options.c | 11 ++---------
> parse-options.h | 2 +-
> 3 files changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/builtin-tag.c b/builtin-tag.c
> index dc3db62..080e04a 100644
> --- a/builtin-tag.c
> +++ b/builtin-tag.c
> @@ -376,8 +376,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
> struct commit_list *with_commit = NULL;
> struct option options[] = {
> OPT_BOOLEAN('l', NULL, &list, "list tag names"),
> - { OPTION_INTEGER, 'n', NULL, &lines, NULL,
> - "print n lines of each tag message",
> + { OPTION_INTEGER, 'n', NULL, &lines, "n",
> + "print <n> lines of each tag message",
> PARSE_OPT_OPTARG, NULL, 1 },
> OPT_BOOLEAN('d', NULL, &delete, "delete tags"),
> OPT_BOOLEAN('v', NULL, &verify, "verify tags"),
> diff --git a/parse-options.c b/parse-options.c
> index b85cab2..48ba62b 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -503,19 +503,12 @@ int usage_with_options_internal(const char * const *usagestr,
> switch (opts->type) {
> case OPTION_ARGUMENT:
> break;
> - case OPTION_INTEGER:
> - if (opts->flags & PARSE_OPT_OPTARG)
> - if (opts->long_name)
> - pos += fprintf(stderr, "[=<n>]");
> - else
> - pos += fprintf(stderr, "[<n>]");
> - else
> - pos += fprintf(stderr, " <n>");
> - break;
> case OPTION_CALLBACK:
> if (opts->flags & PARSE_OPT_NOARG)
> break;
> /* FALLTHROUGH */
> + case OPTION_INTEGER:
> + /* FALLTHROUGH */
> case OPTION_FILENAME:
> /* FALLTHROUGH */
> case OPTION_STRING:
> diff --git a/parse-options.h b/parse-options.h
> index b374ade..b141ae6 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -108,7 +108,7 @@ struct option {
> #define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) }
> #define OPT_SET_INT(s, l, v, h, i) { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) }
> #define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }
> -#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), NULL, (h) }
> +#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), "n", (h) }
> #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) }
> #define OPT_DATE(s, l, v, h) \
> { OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \
Nice code reduction. s/NUMBER/INTEGER/ in the commit message?
By the way, can the switch be replaced by a simple check for
PARSE_OPT_NOARG now?
René
next prev parent reply other threads:[~2009-06-03 10:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-03 7:49 [PATCH] parse-options: make OPT_NUMBER's argh explicit Stephen Boyd
2009-06-03 10:18 ` René Scharfe [this message]
2009-06-03 19:35 ` Stephen Boyd
2009-06-03 20:22 ` René Scharfe
2009-06-04 23:43 ` [PATCHv2 1/2] parse-options: make OPT_INTEGER's " Stephen Boyd
2009-06-04 23:43 ` [PATCHv2 2/2] parse-options: simplify usage argh handling Stephen Boyd
2009-06-06 10:30 ` René Scharfe
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=4A264DFA.3090309@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).