From: Stephen Boyd <bebarino@gmail.com>
To: "Michał Kiedrowicz" <michal.kiedrowicz@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH/RFC] grep: Add --directories option.
Date: Fri, 10 Jul 2009 01:02:22 -0700 [thread overview]
Message-ID: <4A56F58E.1080907@gmail.com> (raw)
In-Reply-To: <1247167228-2466-1-git-send-email-michal.kiedrowicz@gmail.com>
Michał Kiedrowicz wrote:
> @@ -648,10 +658,32 @@ static int help_callback(const struct option *opt, const char *arg, int unset)
> return -1;
> }
>
> +static int directories_callback(const struct option *opt,
> + const char *arg, int unset)
> +{
> + int *recurse = opt->value;
> +
> + if (!arg)
> + return error("switch `d' requires a value");
This isn't needed because OPT_CALLBACK requires an argument always be given.
> +
> + if (!strcmp(arg, "recurse")) {
> + *recurse = 1;
> + return 0;
> + } else if (!strcmp(arg, "skip")) {
> + *recurse = 0;
> + return 0;
> + }
> +
> + fprintf(stderr, "Invalid action `%s'.\n", arg);
> + fprintf(stderr, "Available actions are: recurse skip.\n");
> + return -1;
> +}
> +
I think I would drop the two fprintf's here and just return an error()
saying invalid action. This will in turn cause the usage message to show
up, where you can show the two possible actions.
> @@ -674,6 +706,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
> OPT_SET_INT('I', NULL, &opt.binary,
> "don't match patterns in binary files",
> GREP_BINARY_NOMATCH),
> + OPT_CALLBACK('d', "directories", &recurse, "action",
> + "action to perform when input file is a directory",
> + directories_callback),
> OPT_GROUP(""),
> OPT_BIT('E', "extended-regexp", &opt.regflags,
> "use extended POSIX regular expressions", REG_EXTENDED),
Do you want to allow "--no-directories", I would suggest setting the
PARSE_OPT_NONEG flag to avoid this. Maybe you want to replace "action"
with "recurse|skip" too.
prev parent reply other threads:[~2009-07-10 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-09 19:20 [PATCH/RFC] grep: Add --directories option Michał Kiedrowicz
2009-07-10 7:33 ` René Scharfe
2009-07-10 8:11 ` Junio C Hamano
2009-07-10 16:48 ` Michał Kiedrowicz
2009-07-10 16:41 ` Michał Kiedrowicz
2009-07-10 8:02 ` Stephen Boyd [this message]
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=4A56F58E.1080907@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=michal.kiedrowicz@gmail.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).