From: Junio C Hamano Date: Tue, 30 Jul 2013 22:28:52 GMT Subject: Re: [PATCH] tag: Use OPT_BOOL instead of OPT_BOOLEAN to allow one action multiple times Message-ID: <7vfvuvvg0r.fsf@alter.siamese.dyndns.org> In-Reply-To: <51F83010.2060804@googlemail.com> Stefan Beller writes: > Here is just another idea: > if (cmdmode == 'v') > This may be hard to read, (What is 'v'? I cannot remember > all the alphabet ;)) So maybe we could have an enum instead of > the last parameter? > OPT_CMDMODE( short, long, variable, description, enum) I actually was thinking about going totally in the opposite direction. People who grew up with the old Unix tradition getopt(3) are used to code like this: while ((opt = getopt(ac, av, "abcde")) != -1) { switch (opt) { case 'a': perform_a(); break; case 'b': perform_b(); break; ... } } In other words, the "enum" is most convenient if it matches the "short" option, so instead of having to repeat ourselves over and over, like I did in that illustration patch for builtin/tag.c, e.g. OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'), OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'), we could just do #define OPT_CMDMODE(s, l, v, h) \ { OPTION_CMDMODE, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (s) }