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

Re: [PATCH] rev-parse --parseopt: fix handling of optional arguments

From
Nicolas Vigier <boklm@mars-attacks.org>
Date
Oct 16, 2013, 10:58 UTC
Message-ID
<20131016105811.GA4589@mars-attacks.org>
In-Reply-To
<525E3A80.5000500@viscovery.net>
On Wed, 16 Oct 2013, Johannes Sixt wrote:
Show 24 quoted lines
> Am 10/16/2013 1:57, schrieb Jonathan Nieder:
> > Junio C Hamano wrote:
> > 
> >> You just made these two that the user clearly meant to express two
> >> different things indistinguishable.
> >>
> >> 	opt.sh -S
> >>       opt.sh -S ''
> > [...]
> >> And that is exactly why gitcli.txt tells users to use the 'sticked'
> >> form, and ends the bullet point with:
> >>
> >>    An option that takes optional option-argument must be written in
> >>    the 'sticked' form.
> > 
> > Yes, another possibility in that vein would be to teach rev-parse
> > --parseopt an OPTIONS_LONG_STICKED output format, and then parse with
> 
> Aren't you people trying to solve something that can't besolved? What does
> 
>   git commit -S LICENSE
> 
> mean? Commit the index and sign with the key-id "LICENSE" or commit just
> the file "LICENSE" with the default key-id?

The later, as optional arguments needs to be sticked, but I think this is not related to the problems with --parseopt.

Here is a summary the problems I think we have with --parseopt and proposed solutions. This command makes it possible to parse arguments with a loop like this :

  while test $# != 0
  do
        case "$1" in
        -q)
                GIT_QUIET=t ;;
        -S)
                # do something with $2
                # shift if you think $2 is an optional arg
                ;;
        --)
                shift; break ;;
        esac
        shift
  done
  # do something with the other arguments

And I think the problems with the '?' flag when using this kind of loop are :

 - You don't know if $2 is the optional argument for -S, or the next option
 
 - You can't use '--' as an optional argument to -S, because you don't
   know if '--' is the optional argument to -S, or the separator between
   options and non options.
To fix this, solution 1) is to always include the optional argument in
$2, and set it to '' if it is not set. However this brings the problem
that you can't distinguish between unset argument and empty argument.
The following two become the same :
  ./opt.sh --gpg-id
  ./opt.sh --gpg-id=

Solution 2) is to use a flag like ?<default> as suggested by Jonathan. Now you can distinguish between unset and empty args, but you can't between <default> and unset, but this is probably not a big problem as you can select <default> so that it is a value nobody would want to use.

Solution 3) is the OPTIONS_LONG_STICKED output format suggested by Jonathan. I can't see any problem with this one.

Previous: Jeff KingNext: Nicolas Vigier
Message 11 of 25 in “rev-parse --parseopt: fix handling of optional arguments”
  1. rev-parse --parseopt: fix handling of optional argumentsNicolas Vigier, Oct 15, 2013
  2. Junio C HamanoOct 15, 2013
  3. Nicolas VigierOct 15, 2013
  4. Jonathan NiederOct 15, 2013
  5. Junio C HamanoOct 15, 2013
  6. Jonathan NiederOct 15, 2013
  7. Johannes SixtOct 16, 2013
  8. Jeff KingOct 16, 2013
  9. Junio C HamanoOct 16, 2013
  10. Jeff KingOct 16, 2013
  11. Nicolas VigierOct 16, 2013
  12. Nicolas VigierOct 16, 2013
  13. Jonathan NiederOct 16, 2013
  14. rev-parse --parseopt: add the --sticked-long modeNicolas Vigier, Oct 25, 2013
  15. Junio C HamanoOct 25, 2013
  16. Nicolas VigierOct 25, 2013
  17. Junio C HamanoOct 25, 2013
  18. Philip OakleyOct 26, 2013
  19. Junio C HamanoOct 28, 2013
  20. sticked -> stuckNicolas Vigier, Oct 31, 2013
  21. 1/2 Use the word 'stuck' instead of 'sticked'Nicolas Vigier, Oct 31, 2013
  22. Junio C HamanoOct 31, 2013
  23. 2/2 rev-parse --parseopt: add the --stuck-long modeNicolas Vigier, Oct 31, 2013
  24. Michael HaggertyOct 27, 2013
  25. Nicolas VigierOct 15, 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.