mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-11-07 08:14:02 +01: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() {
|
||||
if [[ "$1" = "-a" || "$1" = "--append" ]]; then
|
||||
eval "$2=(\"\${$2[@]}\" $(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
||||
if [[ "${_ARGV_INDEX}" -ne "$((_ARGV_LAST+1))" ]]; then
|
||||
eval "$2=(\"\${$2[@]}\" $(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
||||
fi
|
||||
else
|
||||
eval "$1=($(printf '%q ' "${_ARGV[@]:$_ARGV_INDEX}"))"
|
||||
fi
|
||||
|
@ -420,13 +420,24 @@ test:fn_getargs_append() {
|
||||
description "Function getargs -a."
|
||||
|
||||
setargs "--two=three" "four"
|
||||
|
||||
|
||||
args=(zero one)
|
||||
getargs -a args
|
||||
|
||||
|
||||
assert_equal 4 "${#args[@]}"
|
||||
assert_equal "zero" "${args[0]}"
|
||||
assert_equal "one" "${args[1]}"
|
||||
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…
Reference in New Issue
Block a user