diff options
Diffstat (limited to 'lib/subcommands/add.bash')
-rw-r--r-- | lib/subcommands/add.bash | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/subcommands/add.bash b/lib/subcommands/add.bash index 2ae6a43..ff1e5e9 100644 --- a/lib/subcommands/add.bash +++ b/lib/subcommands/add.bash @@ -7,6 +7,7 @@ subcommand() { local buffer + local missing_vars=0 export BASHTARD_PLAYBOOK="$1" ; shift @@ -43,6 +44,29 @@ subcommand() # shellcheck disable=SC1090,SC1091 . "$playbook_base/playbook.bash" + # Ensure all required vars are non-empty + debug "bashtard/add" "Checking for \$BASHTARD_PLAYBOOK_VARS" + + for key in "${!BASHTARD_PLAYBOOK_VARS[@]}" + do + # shellcheck disable=SC2086 + in_args "required" ${BASHTARD_PLAYBOOK_VARS[$key]} || continue + + debug "bashtard/add" "Checking \$BASHTARD_PLAYBOOK_VARS[$key]" + + if [[ "$(config "$key")" == "" ]] + then + missing_vars=$(( missing_vars + 1)) + fi + done + + if (( 0 < missing_vars )) + then + emerg "bashtard/add" "One or more required variables are unset" + return 3 + fi + + # Run the playbook if ! playbook_add then crit "bashtard/add" "$BASHTARD_PLAYBOOK reported an error" |