//! The strict confirm prompt, shared by destructive commands. //! //! Before anything that rewrites the working tree, Koh shows what will happen //! and asks one question. Only `y` or `Y` confirms: `yes`, or a //! padded ` y ` all cancel. `--yes` skips the question; without a terminal and //! without `--yes` the command refuses rather than hanging. 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'] } // typed_confirm is confirm for a second, stricter question: the answer has to // match `expected` exactly. `strip` uses it for the typed path. 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 }