summaryrefslogtreecommitdiffstats
path: root/scripts/library/parse_options.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/library/parse_options.sh')
-rw-r--r--scripts/library/parse_options.sh32
1 files changed, 11 insertions, 21 deletions
diff --git a/scripts/library/parse_options.sh b/scripts/library/parse_options.sh
index 48fd42cd..39038de6 100644
--- a/scripts/library/parse_options.sh
+++ b/scripts/library/parse_options.sh
@@ -23,17 +23,15 @@ parse_options() {
[[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1
if (( ! needsargument )); then
- printf ' %s' "$1"
+ OPTRET+=("$1")
else
if [[ -n $2 ]]; then
- printf ' %s ' "$1"
+ OPTRET+=("$1" "$2")
shift
- printf "'%q" "$1"
while [[ -n $2 && ${2:0:1} != "-" ]]; do
shift
- printf " %q" "$1"
+ OPTRET+=("$1")
done
- printf "'"
else
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'$1'" >&2
ret=1
@@ -57,26 +55,22 @@ parse_options() {
( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1
if (( ! needsargument )); then
- printf ' -%s' "${1:i:1}"
+ OPTRET+=("-${1:i:1}")
else
if [[ -n ${1:$i+1} ]]; then
- printf ' -%s ' "${1:i:1}"
- printf "'%q" "${1:$i+1}"
+ OPTRET+=("-${1:i:1}" "${1:i+1}")
while [[ -n $2 && ${2:0:1} != "-" ]]; do
shift
- printf " %q" "$1"
+ OPTRET+=("$1")
done
- printf "'"
else
if [[ -n $2 ]]; then
- printf ' -%s ' "${1:i:1}"
+ OPTRET+=("-${1:i:1}" "$2")
shift
- printf "'%q" "$1"
while [[ -n $2 && ${2:0:1} != "-" ]]; do
shift
- printf " %q" "$1"
+ OPTRET+=("$1")
done
- printf "'"
else
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'-${1:i:1}'" >&2
@@ -91,15 +85,11 @@ parse_options() {
fi
done
else
- unused_options="${unused_options} '$1'"
+ unused_options+=("$1")
fi
shift
done
- printf " --"
- [[ $unused_options ]] && printf ' %s' "${unused_options[@]}"
- [[ $1 ]] && printf " '%s'" "$@"
- printf "\n"
-
+ OPTRET+=('--' "${unused_options[@]}")
return $ret
-} \ No newline at end of file
+}