Add startup confirmation to disk utilities

This commit is contained in:
dido committed 2026-09-27 12:53:24 +03:00
1 parent c777cf115b
commit 33c4229848
5 files changed
+48 -1

No files matched your search

+27
View File
@@ -54,6 +54,33 @@ common::log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >&2
}
# common::confirm returns success only when the user answers yes.
# A no answer or end-of-input cancels the caller; invalid answers are retried.
common::confirm() {
local prompt="$1"
local answer
while true; do
if ! read -r -p "${prompt} [yes/no]: " answer; then
common::log "No response received; cancelling."
return 1
fi
case "${answer,,}" in
yes)
return 0
;;
no)
common::log "Cancelled by user."
return 1
;;
*)
printf "Please answer 'yes' or 'no'.\n" >&2
;;
esac
done
}
# common::require_cmd fails fast with a clear message if a required
# external command is missing from PATH, instead of letting the script
# fail later with a cryptic "command not found".