feat: reserve "all" as a keyword and add shared confirmation helper

This commit is contained in:
Lewis Wynne 2026-04-02 18:35:59 +01:00
parent d73ebdbddd
commit 79e90ed8ce
2 changed files with 41 additions and 0 deletions

34
nag
View file

@ -210,6 +210,36 @@ _piped_input() {
! _interactive_input
}
# Usage:
# _confirm_action <verb> <count> <tag>
#
# 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 <name> <description>
# describe --get <name>
@ -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

View file

@ -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" ]]
}