mirror of
https://github.com/tests-always-included/mo.git
synced 2024-12-18 16:27:52 +00:00
Pass arguments to function as environment variable MO_ARGS
This commit is contained in:
parent
eac2685632
commit
fcedd32155
10
mo
10
mo
@ -62,6 +62,8 @@
|
||||
# options and arguments. This puts the content from the
|
||||
# template directly into an eval statement. Use with
|
||||
# extreme care.
|
||||
# MO_ARGS - Arguments passed to the function,
|
||||
# only if MO_ALLOW_FUNCTION_ARGUMENTS is unset
|
||||
# MO_FAIL_ON_UNSET - When set to a non-empty value, expansion of an unset
|
||||
# env variable will be aborted with an error.
|
||||
# MO_FALSE_IS_EMPTY - When set to a non-empty value, the string "false"
|
||||
@ -156,14 +158,14 @@ mo() (
|
||||
moCallFunction() {
|
||||
local moArgs
|
||||
|
||||
moArgs=()
|
||||
|
||||
# shellcheck disable=SC2031
|
||||
if [[ -n "${MO_ALLOW_FUNCTION_ARGUMENTS-}" ]]; then
|
||||
moArgs=$3
|
||||
echo -n "$2" | eval "$1" "$moArgs"
|
||||
else
|
||||
moTrimWhitespace moArgs "$3"
|
||||
echo -n "$2" | MO_ARGS="$moArgs" eval "$1"
|
||||
fi
|
||||
|
||||
echo -n "$2" | eval "$1" "$moArgs"
|
||||
}
|
||||
|
||||
|
||||
|
3
tests/function-args-read.env
Normal file
3
tests/function-args-read.env
Normal file
@ -0,0 +1,3 @@
|
||||
testArgs() {
|
||||
echo "$MO_ARGS"
|
||||
}
|
4
tests/function-args-read.expected
Normal file
4
tests/function-args-read.expected
Normal file
@ -0,0 +1,4 @@
|
||||
No args: [] - done
|
||||
One arg: [one] - done
|
||||
Multiple arguments: [aa bb cc 'x' " ! {[_.|] - done
|
||||
Evil: [bla; cat /etc/issue] - done
|
4
tests/function-args-read.template
Normal file
4
tests/function-args-read.template
Normal file
@ -0,0 +1,4 @@
|
||||
No args: [{{testArgs}}] - done
|
||||
One arg: [{{testArgs one}}] - done
|
||||
Multiple arguments: [{{testArgs aa bb cc 'x' " ! {[_.| }}] - done
|
||||
Evil: [{{testArgs bla; cat /etc/issue}}] - done
|
Loading…
Reference in New Issue
Block a user