feat: interactive confirmation for tagged stop and skip

This commit is contained in:
Lewis Wynne 2026-04-02 16:57:05 +01:00
parent 8cf79c854b
commit d73ebdbddd
4 changed files with 42 additions and 14 deletions

View file

@ -133,7 +133,7 @@ Usage:
nag stop <id|tag> nag stop <id|tag>
Description: Description:
Stop an alarm by ID, or stop all alarms with a tag (requires -f). Stop an alarm by ID, or stop all alarms with a tag.
``` ```
#### `nag skip` #### `nag skip`
@ -151,7 +151,7 @@ Usage:
Description: Description:
Skip the next occurrence of a repeating alarm (reschedule without firing). Skip the next occurrence of a repeating alarm (reschedule without firing).
For one-shot alarms, this deletes them. With a tag, applies to all For one-shot alarms, this deletes them. With a tag, applies to all
matching alarms (requires -f). matching alarms.
``` ```
#### `nag tag` #### `nag tag`

44
nag
View file

@ -1303,7 +1303,7 @@ Usage:
${_ME} stop <id|tag> ${_ME} stop <id|tag>
Description: Description:
Stop an alarm by ID, or stop all alarms with a tag (requires -f). Stop an alarm by ID, or stop all alarms with a tag.
HEREDOC HEREDOC
stop() { stop() {
local _target="${1:-}" local _target="${1:-}"
@ -1385,9 +1385,23 @@ _stop_by_tag() {
if (( ! _YES )) if (( ! _YES ))
then then
_release_lock if _interactive_input
printf "Would stop %s alarm(s) tagged [%s]. Pass -f to confirm.\\n" "${#_matched[@]}" "${_tag}" then
return 0 printf "Stop %s alarm(s) tagged [%s]? [y/N] " "${#_matched[@]}" "${_tag}"
local _reply
read -r _reply
case "${_reply}" in
[yY]*) ;;
*)
_release_lock
return 0
;;
esac
else
_release_lock
printf "Stop %s alarm(s) tagged [%s]? Pass -f to confirm.\\n" "${#_matched[@]}" "${_tag}"
return 0
fi
fi fi
if (( ${#_new_alarms[@]} == 0 )) if (( ${#_new_alarms[@]} == 0 ))
@ -1419,7 +1433,7 @@ Usage:
Description: Description:
Skip the next occurrence of a repeating alarm (reschedule without firing). Skip the next occurrence of a repeating alarm (reschedule without firing).
For one-shot alarms, this deletes them. With a tag, applies to all For one-shot alarms, this deletes them. With a tag, applies to all
matching alarms (requires -f). matching alarms.
HEREDOC HEREDOC
skip() { skip() {
local _target="${1:-}" local _target="${1:-}"
@ -1513,9 +1527,23 @@ _skip_by_tag() {
if (( ! _YES )) if (( ! _YES ))
then then
_release_lock if _interactive_input
printf "Would skip %s alarm(s) tagged [%s]. Pass -f to confirm.\\n" "${_match_count}" "${_tag}" then
return 0 printf "Skip %s alarm(s) tagged [%s]? [y/N] " "${_match_count}" "${_tag}"
local _reply
read -r _reply
case "${_reply}" in
[yY]*) ;;
*)
_release_lock
return 0
;;
esac
else
_release_lock
printf "Skip %s alarm(s) tagged [%s]? Pass -f to confirm.\\n" "${_match_count}" "${_tag}"
return 0
fi
fi fi
for _line in "${_ALARMS[@]:-}" for _line in "${_ALARMS[@]:-}"

View file

@ -36,9 +36,9 @@ load test_helper
@test "skip by tag requires -f" { @test "skip by tag requires -f" {
run_nag every day "tomorrow 3pm" "daily work" run_nag every day "tomorrow 3pm" "daily work"
run_nag tag 1 work run_nag tag 1 work
run "${_NAG}" skip work run "${_NAG}" skip work < /dev/null
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "Would skip" ]] [[ "${output}" =~ "Skip" ]]
[[ "${output}" =~ "-f" ]] [[ "${output}" =~ "-f" ]]
} }

View file

@ -36,9 +36,9 @@ load test_helper
@test "stop by tag requires -f" { @test "stop by tag requires -f" {
run_nag at "tomorrow 3pm" "tagged alarm" run_nag at "tomorrow 3pm" "tagged alarm"
run_nag tag 1 work run_nag tag 1 work
run "${_NAG}" stop work run "${_NAG}" stop work < /dev/null
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "Would stop" ]] [[ "${output}" =~ "Stop" ]]
[[ "${output}" =~ "-f" ]] [[ "${output}" =~ "-f" ]]
[ -s "${NAG_DIR}/alarms" ] [ -s "${NAG_DIR}/alarms" ]
} }