diff --git a/nag b/nag index c50c815..20383d6 100755 --- a/nag +++ b/nag @@ -210,6 +210,36 @@ _piped_input() { ! _interactive_input } +# Usage: +# _confirm_action +# +# Prompts the user for confirmation before performing a bulk action on +# tagged alarms. Skipped when -f (force/_YES) is set. In non-interactive +# mode, prints a message asking the caller to pass -f. +# +# Exit / Error Status: +# 0 (success, true) If the action is confirmed. +# 1 (error, false) If the action is denied or non-interactive without -f. +_confirm_action() { + local _verb="${1}" _count="${2}" _tag="${3}" + + (( _YES )) && return 0 + + if _interactive_input + then + printf "%s %s alarm(s) tagged [%s]? [y/N] " "${_verb}" "${_count}" "${_tag}" + local _reply + read -r _reply + case "${_reply}" in + [yY]*) return 0 ;; + *) return 1 ;; + esac + else + printf "%s %s alarm(s) tagged [%s]? Pass -f to confirm.\n" "${_verb}" "${_count}" "${_tag}" + return 1 + fi +} + # Usage: # describe # describe --get @@ -1889,6 +1919,10 @@ tag() { then _exit_1 printf "Tag cannot be a number: %s\\n" "${_tag}" fi + if [[ "${_tag}" == "all" ]] + then + _exit_1 printf "Tag name 'all' is reserved.\\n" + fi done _acquire_lock diff --git a/test/tag.bats b/test/tag.bats index 3c2c4e7..49cbb5e 100644 --- a/test/tag.bats +++ b/test/tag.bats @@ -109,3 +109,10 @@ load test_helper run_nag untag [ "${status}" -eq 1 ] } + +@test "tag rejects 'all' as a tag name" { + run_nag at "tomorrow 3pm" "test" + run_nag tag 1 all + [ "${status}" -eq 1 ] + [[ "${output}" =~ "reserved" ]] +}