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\n")" "'$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\n")" "'-${1:i:1}'" >&2 ret=1 -- 1.7.6