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

From: Jonathan Nieder <[email-masked]>
Date: Tue, 15 Oct 2013 16:57:39 -0700

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

	while :
	do
		case $1 in
		--gpg-sign)
			... no keyid ...
			;;
		--gpg-sign=*)
			keyid=${1#--gpg-sign=}
			...
			;;
		esac
		shift
	done

This 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
	done

but it mishandles "--gpg-sign=" with empty argument.

Jonathan