All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Nicolas Vigier <boklm@mars-attacks.org>,
	git@vger.kernel.org, Pierre Habouzit <madcoder@debian.org>
Subject: Re: [PATCH] rev-parse --parseopt: fix handling of optional arguments
Date: Tue, 15 Oct 2013 16:33:27 -0700	[thread overview]
Message-ID: <xmqqfvs29kjc.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20131015231427.GF9464@google.com> (Jonathan Nieder's message of "Tue, 15 Oct 2013 16:14:27 -0700")

Jonathan Nieder <jrnieder@gmail.com> writes:

> Nicolas Vigier wrote:
>
>>   $ cat /tmp/opt.sh
>>   #!/bin/sh
>>   OPTIONS_SPEC="\
>>   git [options]
>>   --
>>   q,quiet         be quiet
>>   S,gpg-sign?     GPG-sign commit"
>>   echo "$OPTIONS_SPEC" | git rev-parse --parseopt $parseopt_extra -- "$@"
>>
>> Then the following two commands give us the same result :
>>
>>   $ /tmp/opt.sh -S -q
>>   set -- -S -q --
>>   $ /tmp/opt.sh -S-q
>>   set -- -S '-q' --
>>
>> We cannot know if '-q' is an argument to '-S' or a new option.
>
> Hmph.
>
> As Junio mentioned, inserting '' would be a backward-incompatible
> change.  I don't think it's worth breaking existing scripts.  Probably
> what is needed is a new parseopt special character with the new
> semantics (e.g.,
>
> 	Use ?? to mean the option has an optional argument.  If the
> 	option is supplied without its argument, the argument is taken
> 	to be ''.
>
> or something like
>
> 	Use ?<default> to mean the option has an optional argument.  If
> 	the option is supplied without its argument and <default> is
> 	nonempty, the argument is taken to be <default>.
>
> ).
>
> Sensible?

You just made these two that the user clearly meant to express two
different things indistinguishable.

	opt.sh -S
        opt.sh -S ''

So I do not think it is sensible. In fact, I do not think there is
any sensible way to handle a shortopt with optional parameter that
is not at the end of the command line.

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.

That still does not give the command line a way to express an option
that could take an optional argument without the optional argument
in the middle of the command line, though.

  reply	other threads:[~2013-10-15 23:33 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 [this message]
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
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=xmqqfvs29kjc.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=boklm@mars-attacks.org \
    --cc=git@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.