Re: [PATCH] rev-parse --parseopt: fix handling of optional arguments
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Oct 15, 2013, 23:57 UTC
- Message-ID
- <20131015235739.GI9464@google.com>
- In-Reply-To
- <xmqqfvs29kjc.fsf@gitster.dls.corp.google.com>
Junio C Hamano wrote:
Show 5 quoted lines
> You just made these two that the user clearly meant to express two > different things indistinguishable. > > opt.sh -S > opt.sh -S ''
[...]
Show 5 quoted lines
> 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
while :
do
case $1 in
--gpg-sign)
... no keyid ...
;;
--gpg-sign=*)
keyid=${1#--gpg-sign=}
...
;;
esac
shift
doneThis still leaves
opt.sh -S and
opt.sh -S''
indistinguishable. Given what the shell passes to execve, I think that's ok.
The analagous method without preferring long options could work almost as well:
while :
do
case $1 in
-S)
... no keyid ...
;;
-S?*)
keyid=${1#-S}
...
;;
esac
shift
donebut it mishandles "--gpg-sign=" with empty argument.
Jonathan