[pacman-dev] [PATCH 3/3] parse_options: accept multiple arguments

Allan McRae allan at archlinux.org
Tue Jul 5 09:50:33 EDT 2011


On 05/07/11 22:19, Dave Reisner wrote:
> On Tue, Jul 05, 2011 at 09:51:31PM +1000, Allan McRae wrote:
>> Allow command-line options to accept multiple arguments without
>> additional quoting by taking the list of arguments until one
>> starting with a "-" is reached.
>>
>> The only current use of this is the --pkg option in makepkg.  This
>> allows (e.g.)
>>
>> makepkg --pkg foo bar
>>
>> and packages "foo" and "bar" will be built.
>>
>> Signed-off-by: Allan McRae<allan at archlinux.org>
>> ---
>>   scripts/library/parse_options.sh |   21 ++++++++++++++++++---
>>   1 files changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/scripts/library/parse_options.sh b/scripts/library/parse_options.sh
>> index 49cbb60..a2f9c1b 100644
>> --- a/scripts/library/parse_options.sh
>> +++ b/scripts/library/parse_options.sh
>> @@ -28,7 +28,12 @@ parse_options() {
>>   						if [[ -n $2 ]]; then
>>   							printf ' %s' "$1"
>>   							shift
>> -							printf " '%s'" "$1"
>> +							local arguments="$1"
>> +							while [[ -n $2&&  ${2:0:1} != "-" ]]; do
>> +								shift
>> +								arguments+=" $1"
>> +							done
>> +							printf " '%s'" "$arguments"
>
> Does this ensure properly quoted multi word arguments are preserved?
> Wouldn't it be easier to use an array and print with %q tokens? Same for
> the next two instances.

No it doesn't...   and while this currently does not matter, it will 
matter if the --add option in pacman-key if files are passed that have 
spaces.   Will fix.

Allan





More information about the pacman-dev mailing list