From f980a4a4e272a854d3023a5c9f67960e9b8c147c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 3 Aug 2023 00:50:02 +0300 Subject: [PATCH] [terminal] Added flag 'AlwaysYes' --- CHANGELOG.md | 4 ++++ ek.go | 2 +- terminal/terminal.go | 8 ++++++++ terminal/terminal_windows.go | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ba0a61..cfbff4fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 12.75.0 + +* `[terminal]` Added flag `AlwaysYes`, if set `ReadAnswer` will always return true without reading user input (_useful for working with option for forced actions_) + ### 12.74.0 * `[timeutil]` Added method `PrettyDurationSimple` for printing duration in simple format diff --git a/ek.go b/ek.go index 8dc5a8d6..3786e3df 100644 --- a/ek.go +++ b/ek.go @@ -20,7 +20,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.74.0" +const VERSION = "12.75.0" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/terminal/terminal.go b/terminal/terminal.go index 39db8327..b4816f37 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -73,6 +73,10 @@ var ( InfoPrefix = "" ) +// AlwaysYes is a flag, if set ReadAnswer will always return true (useful for working +// with option for forced actions) +var AlwaysYes = false + // ////////////////////////////////////////////////////////////////////////////////// // var tmux int8 @@ -86,6 +90,10 @@ func Read(title string, nonEmpty bool) (string, error) { // ReadAnswer reads user's answer for yes/no question func ReadAnswer(title string, defaultAnswers ...string) (bool, error) { + if AlwaysYes { + return true, nil + } + var defaultAnswer string if len(defaultAnswers) != 0 { diff --git a/terminal/terminal_windows.go b/terminal/terminal_windows.go index bda33281..3eb16278 100644 --- a/terminal/terminal_windows.go +++ b/terminal/terminal_windows.go @@ -60,6 +60,10 @@ var ( InfoPrefix = "" ) +// ❗ AlwaysYes is a flag, if set ReadAnswer will always return true (useful for working +// with option for forced actions) +var AlwaysYes = false + // ////////////////////////////////////////////////////////////////////////////////// // // ❗ Read reads user's input