//! Confirmation shared by destructive commands. //! //! Only y or Y consents; --yes supplies consent without a prompt. //! Strip's exact-path check still requires a terminal. module cli import os pub fn interactive() bool { return os.is_atty(0) != 0 } pub fn confirm(yes bool) !bool { if yes { return true } if !interactive() { return error('needs --yes when not interactive') } done_working() eprint(' continue? [y/N] ') answer := os.get_line() eprintln('') return answer.trim_right('\r') in ['y', 'Y'] } /// Require an exact answer for confirmations that --yes must not bypass. pub fn typed_confirm(prompt_text string, expected string) bool { done_working() eprint(' ${prompt_text} ') answer := os.get_line() eprintln('') return answer.trim_right('\r') == expected }