mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-13 21:05:05 -05:00
Revert "parseopts: normalize options into an array"
This was really only half a fix for FS#28445, as it still doesn't correctly handle the case of filenames with spaces. In the short term, there is no obvious fix for this. In the long term, I believe the correct decision is to rewrite the options parser to be more in line with GNU getopt_long. This reverts commits:ca41427141
.969dcddbdf
.
This commit is contained in:
parent
297916e6a2
commit
3c5d5a19b3
@ -3,7 +3,7 @@ parse_options() {
|
|||||||
local short_options=$1; shift;
|
local short_options=$1; shift;
|
||||||
local long_options=$1; shift;
|
local long_options=$1; shift;
|
||||||
local ret=0;
|
local ret=0;
|
||||||
local unused_options=()
|
local unused_options=""
|
||||||
local i
|
local i
|
||||||
|
|
||||||
while [[ -n $1 ]]; do
|
while [[ -n $1 ]]; do
|
||||||
@ -23,15 +23,17 @@ parse_options() {
|
|||||||
[[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1
|
[[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1
|
||||||
|
|
||||||
if (( ! needsargument )); then
|
if (( ! needsargument )); then
|
||||||
OPTRET+=("$1")
|
printf ' %s' "$1"
|
||||||
else
|
else
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
OPTRET+=("$1" "$2")
|
printf ' %s ' "$1"
|
||||||
shift
|
shift
|
||||||
|
printf "'%q" "$1"
|
||||||
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
||||||
shift
|
shift
|
||||||
OPTRET+=("$1")
|
printf " %q" "$1"
|
||||||
done
|
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,22 +57,26 @@ parse_options() {
|
|||||||
( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1
|
( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1
|
||||||
|
|
||||||
if (( ! needsargument )); then
|
if (( ! needsargument )); then
|
||||||
OPTRET+=("-${1:i:1}")
|
printf ' -%s' "${1:i:1}"
|
||||||
else
|
else
|
||||||
if [[ -n ${1:$i+1} ]]; then
|
if [[ -n ${1:$i+1} ]]; then
|
||||||
OPTRET+=("-${1:i:1}" "${1:i+1}")
|
printf ' -%s ' "${1:i:1}"
|
||||||
|
printf "'%q" "${1:$i+1}"
|
||||||
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
||||||
shift
|
shift
|
||||||
OPTRET+=("$1")
|
printf " %q" "$1"
|
||||||
done
|
done
|
||||||
|
printf "'"
|
||||||
else
|
else
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
OPTRET+=("-${1:i:1}" "$2")
|
printf ' -%s ' "${1:i:1}"
|
||||||
shift
|
shift
|
||||||
|
printf "'%q" "$1"
|
||||||
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
while [[ -n $2 && ${2:0:1} != "-" ]]; do
|
||||||
shift
|
shift
|
||||||
OPTRET+=("$1")
|
printf " %q" "$1"
|
||||||
done
|
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
|
||||||
@ -85,11 +91,15 @@ parse_options() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
unused_options+=("$1")
|
unused_options="${unused_options} '$1'"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
OPTRET+=('--' "${unused_options[@]}")
|
printf " --"
|
||||||
|
[[ $unused_options ]] && printf ' %s' "${unused_options[@]}"
|
||||||
|
[[ $1 ]] && printf " '%s'" "$@"
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
@ -1918,11 +1918,11 @@ OPT_LONG+=",version,config:"
|
|||||||
|
|
||||||
# Pacman Options
|
# Pacman Options
|
||||||
OPT_LONG+=",noconfirm,noprogressbar"
|
OPT_LONG+=",noconfirm,noprogressbar"
|
||||||
if ! parse_options $OPT_SHORT $OPT_LONG "$@"; then
|
if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then
|
||||||
echo; usage; exit 1 # E_INVALID_OPTION;
|
echo; usage; exit 1 # E_INVALID_OPTION;
|
||||||
fi
|
fi
|
||||||
set -- "${OPTRET[@]}"
|
eval set -- "$OPT_TEMP"
|
||||||
unset OPT_SHORT OPT_LONG OPTRET
|
unset OPT_SHORT OPT_LONG OPT_TEMP
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -469,11 +469,11 @@ OPT_LONG="add::,config:,delete:,edit-key:,export::,finger::,gpgdir:"
|
|||||||
OPT_LONG+=",help,import:,import-trustdb:,init,keyserver:,list-keys::,list-sigs::"
|
OPT_LONG+=",help,import:,import-trustdb:,init,keyserver:,list-keys::,list-sigs::"
|
||||||
OPT_LONG+=",lsign-key:,populate::,recv-keys:,refresh-keys::,updatedb"
|
OPT_LONG+=",lsign-key:,populate::,recv-keys:,refresh-keys::,updatedb"
|
||||||
OPT_LONG+=",verify:,version"
|
OPT_LONG+=",verify:,version"
|
||||||
if ! parse_options $OPT_SHORT $OPT_LONG "$@"; then
|
if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then
|
||||||
echo; usage; exit 1 # E_INVALID_OPTION;
|
echo; usage; exit 1 # E_INVALID_OPTION;
|
||||||
fi
|
fi
|
||||||
set -- "${OPTRET[@]}"
|
eval set -- "$OPT_TEMP"
|
||||||
unset OPT_SHORT OPT_LONG OPTRET
|
unset OPT_SHORT OPT_LONG OPT_TEMP
|
||||||
|
|
||||||
if [[ $1 == "--" ]]; then
|
if [[ $1 == "--" ]]; then
|
||||||
usage;
|
usage;
|
||||||
|
Loading…
Reference in New Issue
Block a user