prompt.v

796 B · raw

1//! Confirmation shared by destructive commands.2//!3//! Only y or Y consents; --yes supplies consent without a prompt.4//! Strip's exact-path check still requires a terminal.56module cli78import os910pub fn interactive() bool {11	return os.is_atty(0) != 012}1314pub fn confirm(yes bool) !bool {15	if yes {16		return true17	}18	if !interactive() {19		return error('needs --yes when not interactive')20	}21	done_working()22	eprint('  continue? [y/N] ')23	answer := os.get_line()24	eprintln('')25	return answer.trim_right('\r') in ['y', 'Y']26}2728/// Require an exact answer for confirmations that --yes must not bypass.29pub fn typed_confirm(prompt_text string, expected string) bool {30	done_working()31	eprint('  ${prompt_text} ')32	answer := os.get_line()33	eprintln('')34	return answer.trim_right('\r') == expected35}