From: Tobias Klauser <tklauser@distanz.ch>
To: Junio C Hamano <gitster@pobox.com>
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>, git@vger.kernel.org
Subject: Re: [PATCH v2 2/4] stripspace: Use parse-options for command-line parsing
Date: Sat, 17 Oct 2015 12:30:32 +0200 [thread overview]
Message-ID: <20151017103032.GC2468@distanz.ch> (raw)
In-Reply-To: <xmqqoafyg2sp.fsf@gitster.mtv.corp.google.com>
On 2015-10-16 at 19:07:34 +0200, Junio C Hamano <gitster@pobox.com> wrote:
> Tobias Klauser <tklauser@distanz.ch> writes:
>
> > Use parse-options to parse command-line options instead of a
> > hand-crafted implementation.
> >
> > This is a preparatory patch to simplify the introduction of the
> > --count-lines option in a follow-up patch.
>
> The second paragraph is probably of much lessor importance than one
> thing you forgot to mention: the users can now use a unique prefix
> of the option and say "stripspace --comment".
I didn't even know about that feature, but now that you've mentioned it
I will certainly make use of it more in the future :) And of course,
I'll adjust the commit message accordingly for v3.
> > +enum stripspace_mode {
> > + STRIP_DEFAULT = 0,
> > + STRIP_COMMENTS,
> > + COMMENT_LINES
> > +};
> >
> > int cmd_stripspace(int argc, const char **argv, const char *prefix)
> > {
> > struct strbuf buf = STRBUF_INIT;
> > - int strip_comments = 0;
> > - enum { INVAL = 0, STRIP_SPACE = 1, COMMENT_LINES = 2 } mode = STRIP_SPACE;
> > -
> > - if (argc == 2) {
> > - if (!strcmp(argv[1], "-s") ||
> > - !strcmp(argv[1], "--strip-comments")) {
> > - strip_comments = 1;
> > - } else if (!strcmp(argv[1], "-c") ||
> > - !strcmp(argv[1], "--comment-lines")) {
> > - mode = COMMENT_LINES;
> > - } else {
> > - mode = INVAL;
> > - }
> > - } else if (argc > 1) {
> > - mode = INVAL;
> > - }
> > -
> > - if (mode == INVAL)
> > - usage(usage_msg);
>
> When given "git stripspace -s blorg", we used to set mode to INVAL
> and then showed the correct usage. But we no longer have a check
> that corresponds to the old INVAL thing, do we? Perhaps check argc
> to detect presence of an otherwise ignored non-option argument
> immediately after parse_options() returns?
Agreed, we should check it. I'll go with the implementation you
suggested in the follow-up message.
> > - if (strip_comments || mode == COMMENT_LINES)
> > + enum stripspace_mode mode = STRIP_DEFAULT;
> > +
> > + const struct option options[] = {
> > + OPT_CMDMODE('s', "strip-comments", &mode,
> > + N_("skip and remove all lines starting with comment character"),
> > + STRIP_COMMENTS),
> > + OPT_CMDMODE('c', "comment-lines", &mode,
> > + N_("prepend comment character and blank to each line"),
> > + COMMENT_LINES),
> > + OPT_END()
> > + };
> > +
> > + argc = parse_options(argc, argv, prefix, options, stripspace_usage,
> > + PARSE_OPT_KEEP_DASHDASH);
>
> What is the point of keep-dashdash here?
Likewise, it shouldn't be there as in your follow-up patch.
next prev parent reply other threads:[~2015-10-17 10:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-16 15:16 [PATCH v2 0/4] stripspace: Implement and use --count-lines option Tobias Klauser
2015-10-16 15:16 ` [PATCH v2 1/4] strbuf: make stripspace() part of strbuf Tobias Klauser
2015-10-16 15:16 ` [PATCH v2 2/4] stripspace: Use parse-options for command-line parsing Tobias Klauser
2015-10-16 17:07 ` Junio C Hamano
2015-10-16 17:29 ` Junio C Hamano
2015-10-17 10:31 ` Tobias Klauser
2015-10-17 21:24 ` Junio C Hamano
2015-10-20 8:48 ` Tobias Klauser
2015-10-20 15:47 ` Junio C Hamano
2015-10-17 10:30 ` Tobias Klauser [this message]
2015-10-16 15:16 ` [PATCH v2 3/4] stripspace: Implement --count-lines option Tobias Klauser
2015-10-17 23:57 ` Eric Sunshine
2015-10-18 17:18 ` Junio C Hamano
2015-10-19 13:46 ` Tobias Klauser
2015-10-19 17:03 ` Christian Couder
2015-10-19 19:24 ` Eric Sunshine
2015-10-19 19:42 ` Matthieu Moy
2015-10-19 13:31 ` Tobias Klauser
2015-10-16 15:16 ` [PATCH v2 4/4] git rebase -i: Use newly added --count-lines option for stripspace Tobias Klauser
2015-10-16 16:41 ` [PATCH v2 0/4] stripspace: Implement and use --count-lines option Junio C Hamano
2015-10-17 10:27 ` Tobias Klauser
2015-10-16 16:54 ` Matthieu Moy
2015-10-17 10:28 ` Tobias Klauser
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=20151017103032.GC2468@distanz.ch \
--to=tklauser@distanz.ch \
--cc=Matthieu.Moy@imag.fr \
--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).