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

Re: parse-options: ambiguous LASTARG_DEFAULT and OPTARG

From
Stephen Boyd <bebarino@gmail.com>
Date
Jun 6, 2009, 20:14 UTC
Message-ID
<4A2ACE32.8080504@gmail.com>
In-Reply-To
<4A2A4534.80604@lsrfire.ath.cx>
René Scharfe wrote:
> PARSE_OPT_OPTARG overrides PARSE_OPT_LASTARG_DEFAULT, as Pierre noted in
> commit 1cc6985c, which introduced the latter, so the two should not be
> used together.

Ok, thanks. This means I used it wrong when I switched over show-branch :-/ I'll have to send a follow-up patch for that.

Show 5 quoted lines
> PARSE_OPT_LASTARG_DEFAULT uses the default value if the option is the
> last one on the command line and requires an explicit argument if it's
> not the last, as you found out above.  That's also what the code says
> and its name implies; the comment in parse-options.h (by yours truly)
> is probably misleading because it doesn't mention this condition.

I was mislead. When I read it I thought I had to use the flag to say that the default value will be used in the case when no argument is given. I completely ignored the LASTARG part (I thought it was referencing the default arg). I think just adding what you said here to parse-options.h will help others to avoid this.

> I don't remember any other program having options with such a
> behaviour; I'm not sure how to stress that --merged needs to be the
> last option, as implied by the help message.

"git tag --contains" is the same. Figuring out a way to say that the syntax changes when it's the last option versus in the middle is not obvious to me either.

Previous: René ScharfeNext: Stephen Boyd
Message 3 of 9 in “parse-options: ambiguous LASTARG_DEFAULT and OPTARG”
  1. Stephen BoydJun 5, 2009
  2. René ScharfeJun 6, 2009
  3. Stephen BoydJun 6, 2009
  4. show-branch: don't use LASTARG_DEFAULT with OPTARGStephen Boyd, Jun 7, 2009
  5. René ScharfeJun 8, 2009
  6. Junio C HamanoJun 8, 2009
  7. parse-options: add parse_options_check to validate option specs.Pierre Habouzit, Jun 9, 2009
  8. Pierre HabouzitJun 12, 2009
  9. René ScharfeJun 12, 2009

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.