From: Junio C Hamano <gitster@pobox.com>
To: Matheus Tavares <matheus.bernardino@usp.br>
Cc: git@vger.kernel.org, szeder.dev@gmail.com,
Johannes.Schindelin@gmx.de, j6t@kdbg.org, peff@peff.net
Subject: Re: [PATCH v2] test-lib: allow short options to be bundled
Date: Sat, 21 Mar 2020 13:07:39 -0700 [thread overview]
Message-ID: <xmqqtv2h8oac.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <7a6a8197dcd58e8690892d03cb904dd1eec5d7c1.1584818457.git.matheus.bernardino@usp.br> (Matheus Tavares's message of "Sat, 21 Mar 2020 16:57:31 -0300")
Matheus Tavares <matheus.bernardino@usp.br> writes:
> - Added a check for bundles containing more than one "option that
> requires args" (e.g. '-rr'), in which case we error-out. We could
> interpret '-rr 1 2' as 'run tests 1 _and_ 2', but the unbundled
> format, '-r 1 -r 2', is not currently interpreted like that (the last
> just overrides the previous). So, for simplicity, let's only forbid
> such bundles for now.
Makes sense. I think this is the best we can do at this moment.
> +opt_required_arg=
> +# $1: option string
> +# $2: name of the var where the arg will be stored
> +mark_option_requires_arg ()
> +{
"{" on the same line, just like you did for parse_option below.
> + if test -n "$opt_required_arg"
> then
> + echo "error: options that require args cannot be bundled" \
> + "together: '$opt_required_arg' and '$1'" >&2
> + exit 1
> fi
> + opt_required_arg=$1
> + store_arg_to=$2
> +}
> +
> +parse_option () {
> + local opt="$1"
> ...
> + case "$opt" in
> + --*)
> + parse_option "$opt" ;;
I think J6t's suggestion to the previous round still has merit here.
> + -?*)
> + # bundled short options must be fed separately to parse_option
> + opt=${opt#-}
> + while test -n "$opt"
> + do
> + extra=${opt#?}
Take the rest of the string after stripping the first one in $extra ...
> + this=${opt%$extra}
... and then strip that tail part from the end, which would give the
first letter in $this.
> + opt=$extra
And the next round will use the remainder after taking $this out
of the bundled options from the front.
Makes sense.
> + parse_option "-$this"
> + done
Thanks
next prev parent reply other threads:[~2020-03-21 20:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-21 3:07 [PATCH] test-lib: allow short options to be stacked Matheus Tavares
2020-03-21 4:53 ` Junio C Hamano
2020-03-21 17:27 ` Matheus Tavares
2020-03-21 6:26 ` Jeff King
2020-03-21 18:50 ` Matheus Tavares Bernardino
2020-03-22 6:49 ` Jeff King
2020-03-22 8:14 ` SZEDER Gábor
2020-03-21 18:57 ` Junio C Hamano
2020-03-21 8:55 ` Johannes Sixt
2020-03-21 18:55 ` Matheus Tavares Bernardino
2020-03-21 20:11 ` Junio C Hamano
2020-03-21 19:57 ` [PATCH v2] test-lib: allow short options to be bundled Matheus Tavares
2020-03-21 20:07 ` Junio C Hamano [this message]
2020-03-21 22:42 ` Matheus Tavares Bernardino
2020-03-22 15:58 ` [PATCH v3] " Matheus Tavares
2020-03-23 20:18 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqtv2h8oac.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=matheus.bernardino@usp.br \
--cc=peff@peff.net \
--cc=szeder.dev@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).