mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
parse_options: implement optional arguments
This allows options specified with a trailing "::" to optionally take arguments. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
ddb8617d96
commit
87ee38d8b3
@ -17,7 +17,12 @@ parse_options() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [[ -n $match ]]; then
|
if [[ -n $match ]]; then
|
||||||
if [[ ${1:2} = $match ]]; then
|
local needsargument=0
|
||||||
|
|
||||||
|
[[ ${match} = ${1:2}: ]] && needsargument=1
|
||||||
|
[[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1
|
||||||
|
|
||||||
|
if (( ! needsargument )); then
|
||||||
printf ' %s' "$1"
|
printf ' %s' "$1"
|
||||||
else
|
else
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
@ -40,7 +45,15 @@ parse_options() {
|
|||||||
elif [[ ${1:0:1} = '-' ]]; then
|
elif [[ ${1:0:1} = '-' ]]; then
|
||||||
for ((i=1; i<${#1}; i++)); do
|
for ((i=1; i<${#1}; i++)); do
|
||||||
if [[ $short_options =~ ${1:i:1} ]]; then
|
if [[ $short_options =~ ${1:i:1} ]]; then
|
||||||
if [[ $short_options =~ ${1:i:1}: ]]; then
|
local needsargument=0
|
||||||
|
|
||||||
|
[[ $short_options =~ ${1:i:1}: && ! $short_options =~ ${1:i:1}:: ]] && needsargument=1
|
||||||
|
[[ $short_options =~ ${1:i:1}:: && \
|
||||||
|
( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1
|
||||||
|
|
||||||
|
if (( ! needsargument )); then
|
||||||
|
printf ' -%s' "${1:i:1}"
|
||||||
|
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 " '%s'" "${1:$i+1}"
|
||||||
@ -55,8 +68,6 @@ parse_options() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
else
|
|
||||||
printf ' -%s' "${1:i:1}"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "@SCRIPTNAME@: $(gettext "unrecognized option") '-${1:i:1}'" >&2
|
echo "@SCRIPTNAME@: $(gettext "unrecognized option") '-${1:i:1}'" >&2
|
||||||
|
Loading…
Reference in New Issue
Block a user