Make _required_arguments required

This commit is contained in:
vlad 2023-03-05 19:42:37 -08:00
parent c7be3223b4
commit de3baf57e3
2 changed files with 23 additions and 1 deletions

View File

@ -38,4 +38,23 @@ testArgumentsNotDeclaredDoNot() {
assertEquals "" "$STDOUT"
}
testRequiredArgumentsAreRequired() {
echo '
#!/usr/bin/env bash
⚡banana() {
_required_argument hello
echo "$_arg_hello"
}
' > go
echo "source $REPO_ROOT/⚡" >> go
chmod +x go
try ./go banana
assertContains "$STDERR" "'hello' is a required argument"
assertEquals 1 "$EXIT_CODE"
}
source $(dirname $0)/runner

5
View File

@ -66,7 +66,10 @@ _argument() {
_required_argument() {
_argument "$@"
if [[ ! -v "_arg_$1" ]]; then
_bad-message "'hello' is a required argument" >&2
exit 1
fi
}
_good-message() {