From: Nicolas Vigier <boklm@mars-attacks.org>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, Pierre Habouzit <madcoder@debian.org>
Subject: Re: [PATCH] rev-parse --parseopt: fix handling of optional arguments
Date: Wed, 16 Oct 2013 12:58:11 +0200 [thread overview]
Message-ID: <20131016105811.GA4589@mars-attacks.org> (raw)
In-Reply-To: <525E3A80.5000500@viscovery.net>
On Wed, 16 Oct 2013, Johannes Sixt wrote:
> 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.
next prev parent reply other threads:[~2013-10-16 10:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-15 12:00 [PATCH] rev-parse --parseopt: fix handling of optional arguments Nicolas Vigier
2013-10-15 22:55 ` Junio C Hamano
2013-10-15 23:47 ` Nicolas Vigier
2013-10-15 23:14 ` Jonathan Nieder
2013-10-15 23:33 ` Junio C Hamano
2013-10-15 23:57 ` Jonathan Nieder
2013-10-16 7:04 ` Johannes Sixt
2013-10-16 8:53 ` Jeff King
2013-10-16 21:40 ` Junio C Hamano
2013-10-16 21:50 ` Jeff King
2013-10-16 10:58 ` Nicolas Vigier [this message]
2013-10-16 14:14 ` Nicolas Vigier
2013-10-16 22:33 ` Jonathan Nieder
2013-10-25 20:18 ` [PATCH] rev-parse --parseopt: add the --sticked-long mode Nicolas Vigier
2013-10-25 22:01 ` Junio C Hamano
2013-10-25 22:52 ` Nicolas Vigier
2013-10-25 22:55 ` Junio C Hamano
2013-10-26 21:55 ` Philip Oakley
2013-10-28 15:47 ` Junio C Hamano
2013-10-31 11:08 ` sticked -> stuck Nicolas Vigier
2013-10-31 11:08 ` [PATCH 1/2] Use the word 'stuck' instead of 'sticked' Nicolas Vigier
2013-10-31 19:35 ` Junio C Hamano
2013-10-31 11:08 ` [PATCH 2/2] rev-parse --parseopt: add the --stuck-long mode Nicolas Vigier
2013-10-27 5:45 ` [PATCH] rev-parse --parseopt: add the --sticked-long mode Michael Haggerty
2013-10-15 23:53 ` [PATCH] rev-parse --parseopt: fix handling of optional arguments Nicolas Vigier
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=20131016105811.GA4589@mars-attacks.org \
--to=boklm@mars-attacks.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=jrnieder@gmail.com \
--cc=madcoder@debian.org \
/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).