Allow passing arguments to functions
This commit is contained in:
2
examples
2
examples
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
⚡️build() {
|
⚡️build() {
|
||||||
_help-line "Build an incredible script" "$@"
|
_help-line "Build an incredible script" "$@"
|
||||||
echo "echo hi" > .generated/potato
|
echo 'echo hi; echo "$@"' > .generated/potato
|
||||||
chmod +x .generated/potato
|
chmod +x .generated/potato
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Look! It's like a task runner!
|
|||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
⚡build() {
|
⚡build() {
|
||||||
echo "echo hi" > .generated/potato
|
echo 'echo hi; echo "$@"' > .generated/potato
|
||||||
chmod +x .generated/potato
|
chmod +x .generated/potato
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,20 @@ testReferingToALightningFunctionWorks() {
|
|||||||
assertContains "$STDOUT" "Good Bye."
|
assertContains "$STDOUT" "Good Bye."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testArgumentsArePassedToLightningFunctions() {
|
||||||
|
echo '
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
⚡hello() { echo "Hello, $@!" ; }
|
||||||
|
' > go
|
||||||
|
|
||||||
|
echo "source $REPO_ROOT/⚡" >> go
|
||||||
|
chmod +x go
|
||||||
|
|
||||||
|
try ./go hello banana
|
||||||
|
assertContains "$STDOUT" "Hello, banana!"
|
||||||
|
}
|
||||||
|
|
||||||
testDefiningALightningFunctionWorksWithSelector16() {
|
testDefiningALightningFunctionWorksWithSelector16() {
|
||||||
echo '
|
echo '
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|||||||
6
⚡
6
⚡
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
redefine-functions-defined-with-selector-16
|
redefine-functions-defined-with-selector-16
|
||||||
if [[ $(type -t "⚡$1") == "function" ]]; then
|
command="$1"
|
||||||
⚡$1
|
shift
|
||||||
|
if [[ $(type -t "⚡$command") == "function" ]]; then
|
||||||
|
⚡$command "$@"
|
||||||
else
|
else
|
||||||
⚡help
|
⚡help
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user