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> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
87ee38d8b3
commit
bfd6d22be2
1 changed files with 23 additions and 7 deletions
|
@ -26,9 +26,14 @@ parse_options() {
|
||||||
printf ' %s' "$1"
|
printf ' %s' "$1"
|
||||||
else
|
else
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
printf ' %s' "$1"
|
printf ' %s ' "$1"
|
||||||
shift
|
shift
|
||||||
printf " '%s'" "$1"
|
printf "'%q" "$1"
|
||||||
|
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
||||||
|
shift
|
||||||
|
printf " %q" "$1"
|
||||||
|
done
|
||||||
|
printf "'"
|
||||||
else
|
else
|
||||||
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'$1'" >&2
|
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'$1'" >&2
|
||||||
ret=1
|
ret=1
|
||||||
|
@ -55,13 +60,24 @@ parse_options() {
|
||||||
printf ' -%s' "${1:i:1}"
|
printf ' -%s' "${1:i:1}"
|
||||||
else
|
else
|
||||||
if [[ -n ${1:$i+1} ]]; then
|
if [[ -n ${1:$i+1} ]]; then
|
||||||
printf ' -%s' "${1:i:1}"
|
printf ' -%s ' "${1:i:1}"
|
||||||
printf " '%s'" "${1:$i+1}"
|
printf "'%q" "${1:$i+1}"
|
||||||
|
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
||||||
|
shift
|
||||||
|
printf " %q" "$1"
|
||||||
|
done
|
||||||
|
printf "'"
|
||||||
else
|
else
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
printf ' -%s' "${1:i:1}"
|
printf ' -%s ' "${1:i:1}"
|
||||||
shift
|
shift
|
||||||
printf " '%s'" "${1}"
|
printf "'%q" "$1"
|
||||||
|
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
||||||
|
shift
|
||||||
|
printf " %q" "$1"
|
||||||
|
done
|
||||||
|
printf "'"
|
||||||
|
|
||||||
else
|
else
|
||||||
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'-${1:i:1}'" >&2
|
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'-${1:i:1}'" >&2
|
||||||
ret=1
|
ret=1
|
||||||
|
|
Loading…
Add table
Reference in a new issue