git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] test-lib: allow short options to be bundled

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2020, 20:07 UTC
Message-ID
<xmqqtv2h8oac.fsf@gitster.c.googlers.com>
In-Reply-To
<7a6a8197dcd58e8690892d03cb904dd1eec5d7c1.1584818457.git.matheus.bernardino@usp.br>
Matheus Tavares <matheus.bernardino@usp.br> writes:
Show 6 quoted lines
> - 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.
Show 5 quoted lines
> +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.
Show 16 quoted lines
> +	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.
Show 6 quoted lines
> +	-?*)
> +		# 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
Previous: Matheus TavaresNext: Matheus Tavares Bernardino
Message 13 of 16 in “test-lib: allow short options to be stacked”
  1. test-lib: allow short options to be stackedMatheus Tavares, Mar 21, 2020
  2. Junio C HamanoMar 21, 2020
  3. Matheus TavaresMar 21, 2020
  4. Jeff KingMar 21, 2020
  5. Matheus Tavares BernardinoMar 21, 2020
  6. Jeff KingMar 22, 2020
  7. SZEDER GáborMar 22, 2020
  8. Junio C HamanoMar 21, 2020
  9. Johannes SixtMar 21, 2020
  10. Matheus Tavares BernardinoMar 21, 2020
  11. Junio C HamanoMar 21, 2020
  12. test-lib: allow short options to be bundledMatheus Tavares, Mar 21, 2020
  13. Junio C HamanoMar 21, 2020
  14. Matheus Tavares BernardinoMar 21, 2020
  15. test-lib: allow short options to be bundledMatheus Tavares, Mar 22, 2020
  16. Junio C HamanoMar 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.