feat: interactive confirmation for tagged stop and skip
This commit is contained in:
parent
8cf79c854b
commit
d73ebdbddd
4 changed files with 42 additions and 14 deletions
|
|
@ -133,7 +133,7 @@ Usage:
|
|||
nag stop <id|tag>
|
||||
|
||||
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`
|
||||
|
|
@ -151,7 +151,7 @@ Usage:
|
|||
Description:
|
||||
Skip the next occurrence of a repeating alarm (reschedule without firing).
|
||||
For one-shot alarms, this deletes them. With a tag, applies to all
|
||||
matching alarms (requires -f).
|
||||
matching alarms.
|
||||
```
|
||||
|
||||
#### `nag tag`
|
||||
|
|
|
|||
44
nag
44
nag
|
|
@ -1303,7 +1303,7 @@ Usage:
|
|||
${_ME} stop <id|tag>
|
||||
|
||||
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
|
||||
stop() {
|
||||
local _target="${1:-}"
|
||||
|
|
@ -1385,9 +1385,23 @@ _stop_by_tag() {
|
|||
|
||||
if (( ! _YES ))
|
||||
then
|
||||
_release_lock
|
||||
printf "Would stop %s alarm(s) tagged [%s]. Pass -f to confirm.\\n" "${#_matched[@]}" "${_tag}"
|
||||
return 0
|
||||
if _interactive_input
|
||||
then
|
||||
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
|
||||
|
||||
if (( ${#_new_alarms[@]} == 0 ))
|
||||
|
|
@ -1419,7 +1433,7 @@ Usage:
|
|||
Description:
|
||||
Skip the next occurrence of a repeating alarm (reschedule without firing).
|
||||
For one-shot alarms, this deletes them. With a tag, applies to all
|
||||
matching alarms (requires -f).
|
||||
matching alarms.
|
||||
HEREDOC
|
||||
skip() {
|
||||
local _target="${1:-}"
|
||||
|
|
@ -1513,9 +1527,23 @@ _skip_by_tag() {
|
|||
|
||||
if (( ! _YES ))
|
||||
then
|
||||
_release_lock
|
||||
printf "Would skip %s alarm(s) tagged [%s]. Pass -f to confirm.\\n" "${_match_count}" "${_tag}"
|
||||
return 0
|
||||
if _interactive_input
|
||||
then
|
||||
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
|
||||
|
||||
for _line in "${_ALARMS[@]:-}"
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ load test_helper
|
|||
@test "skip by tag requires -f" {
|
||||
run_nag every day "tomorrow 3pm" "daily work"
|
||||
run_nag tag 1 work
|
||||
run "${_NAG}" skip work
|
||||
run "${_NAG}" skip work < /dev/null
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Would skip" ]]
|
||||
[[ "${output}" =~ "Skip" ]]
|
||||
[[ "${output}" =~ "-f" ]]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ load test_helper
|
|||
@test "stop by tag requires -f" {
|
||||
run_nag at "tomorrow 3pm" "tagged alarm"
|
||||
run_nag tag 1 work
|
||||
run "${_NAG}" stop work
|
||||
run "${_NAG}" stop work < /dev/null
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Would stop" ]]
|
||||
[[ "${output}" =~ "Stop" ]]
|
||||
[[ "${output}" =~ "-f" ]]
|
||||
[ -s "${NAG_DIR}/alarms" ]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue