mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
lib: Fix 'getargs --append' adding an empty value to the array
This commit is contained in:
parent
47152d69c3
commit
93e2e4d048
@ -57,7 +57,9 @@ setargs() {
|
|||||||
# getargs remaining_args
|
# getargs remaining_args
|
||||||
getargs() {
|
getargs() {
|
||||||
if [[ "$1" = "-a" || "$1" = "--append" ]]; then
|
if [[ "$1" = "-a" || "$1" = "--append" ]]; then
|
||||||
|
if [[ "${_ARGV_INDEX}" -ne "$((_ARGV_LAST+1))" ]]; then
|
||||||
eval "$2=(\"\${$2[@]}\" $(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
eval "$2=(\"\${$2[@]}\" $(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
eval "$1=($(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
eval "$1=($(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
||||||
fi
|
fi
|
||||||
|
@ -429,4 +429,15 @@ test:fn_getargs_append() {
|
|||||||
assert_equal "one" "${args[1]}"
|
assert_equal "one" "${args[1]}"
|
||||||
assert_equal "--two=three" "${args[2]}"
|
assert_equal "--two=three" "${args[2]}"
|
||||||
assert_equal "four" "${args[3]}"
|
assert_equal "four" "${args[3]}"
|
||||||
|
|
||||||
|
# Ensure it doesn't append empty strings.
|
||||||
|
args=()
|
||||||
|
setargs "zero" "one"
|
||||||
|
getargs -a args
|
||||||
|
assert_equal 2 "${#args[@]}"
|
||||||
|
|
||||||
|
args=(zero one)
|
||||||
|
setargs
|
||||||
|
getargs -a args
|
||||||
|
assert_equal 2 "${#args[@]}"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user