FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-05-2011, 11:51 AM
Allan McRae
 
Default parse_options: accept multiple arguments

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@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"
else
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument
")" "'$1'" >&2
ret=1
@@ -56,12 +61,22 @@ parse_options() {
else
if [[ -n ${1:$i+1} ]]; then
printf ' -%s' "${1:i:1}"
- printf " '%s'" "${1:$i+1}"
+ local arguments="${1:$i+1}"
+ while [[ -n $2 && ${2:0:1} != "-" ]]; do
+ shift
+ arguments+=" $1"
+ done
+ printf " '%s'" "$arguments"
else
if [[ -n $2 ]]; then
printf ' -%s' "${1:i:1}"
shift
- printf " '%s'" "${1}"
+ local arguments="$1"
+ while [[ -n $2 && ${2:0:1} != "-" ]]; do
+ shift
+ arguments+=" $1"
+ done
+ printf " '%s'" "$arguments"
else
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument
")" "'-${1:i:1}'" >&2
ret=1
--
1.7.6
 

Thread Tools




All times are GMT. The time now is 05:21 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org