git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] tag: Use OPT_BOOL instead of OPT_BOOLEAN to allow one action multiple times

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 30, 2013, 22:28 UTC
Message-ID
<7vfvuvvg0r.fsf@alter.siamese.dyndns.org>
In-Reply-To
<51F83010.2060804@googlemail.com>
Stefan Beller <stefanbeller@googlemail.com> writes:
Show 6 quoted lines
> 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) }
Previous: Stefan BellerNext: Stefan Beller
Message 6 of 11 in “tag: Use OPT_BOOL instead of OPT_BOOLEAN to allow one action multiple times”
  1. tag: Use OPT_BOOL instead of OPT_BOOLEAN to allow one action multiple timesStefan Beller, Jul 30, 2013
  2. Junio C HamanoJul 30, 2013
  3. Stefan BellerJul 30, 2013
  4. Junio C HamanoJul 30, 2013
  5. Stefan BellerJul 30, 2013
  6. Junio C HamanoJul 30, 2013
  7. Stefan BellerJul 31, 2013
  8. Junio C HamanoJul 31, 2013
  9. Stefano LattariniAug 17, 2013
  10. Jonathan NiederAug 17, 2013
  11. Junio C HamanoAug 18, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.