diff --git a/scripts/lib/bashy-core/arg-processor.sh b/scripts/lib/bashy-core/arg-processor.sh index a289726..05c7b82 100644 --- a/scripts/lib/bashy-core/arg-processor.sh +++ b/scripts/lib/bashy-core/arg-processor.sh @@ -905,7 +905,7 @@ function _argproc_parse-enum { local value="$1" local values - set-array-from-vals values "${value}" \ + set-array-from-vals --quiet values "${value}" \ || return "$?" if (( ${#values[@]} == 0 )); then @@ -1072,7 +1072,7 @@ function _argproc_statements-from-args { ;; '[]=') # Multi-value option. Parse the value into elements. - if set-array-from-vals values "${value}"; then + if set-array-from-vals --quiet values "${value}"; then _argproc_statements+=( "${handler} $(vals "${values[@]}")") else diff --git a/scripts/lib/bashy-core/misc.sh b/scripts/lib/bashy-core/misc.sh index ecaae20..69ce6df 100644 --- a/scripts/lib/bashy-core/misc.sh +++ b/scripts/lib/bashy-core/misc.sh @@ -91,20 +91,28 @@ function set-array-from-lines { # Reverse of `vals`: Assigns parsed elements of the given multi-value string # (as produced by `vals` or similar) into the indicated variable, as an array. -# Values must be separated by at least one whitespace character. +# Values must be separated by at least one whitespace character. The option +# `--quiet` suppresses error output. function set-array-from-vals { + # Note: Because we use `eval`, local variables are given name prefixes to + # avoid conflicts with the caller. + local _bashy_quiet=0 + if [[ $1 == '--quiet' ]]; then + _bashy_quiet=1 + shift + fi + if (( $# != 2 )); then error-msg --file-line=1 'Missing argument(s) to `set-array-from-vals`.' return 1 fi - # Note: Because we use `eval`, local variables are given name prefixes to - # avoid conflicts with the caller. local _bashy_name="$1" - local _bashy_value="$2" + local _bashy_origValue="$2" - local _bashy_notsp=$'[^ \n\r\t]' - local _bashy_space=$'[ \n\r\t]' + local _bashy_value="${_bashy_origValue}" + local _bashy_notsp=$'[^ \n\r\t]' # Regex constant. + local _bashy_space=$'[ \n\r\t]' # Ditto. # Trim _ending_ whitespace, and prefix `value` with a space, the latter to # maintain the constraint that values are whitespace-separated. @@ -134,6 +142,10 @@ function set-array-from-vals { done if ! [[ ${_bashy_value} =~ ^${_bashy_space}*$ ]]; then + if (( !_bashy_quiet )); then + error-msg 'Invalid `vals`-style multi-value string:' + error-msg " $(vals "${_bashy_origValue}")" + fi return 1 fi