Skip to content

Commit

Permalink
[terminal] Improve 'AlwaysYes' flag handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Aug 3, 2023
1 parent f980a4a commit 52086c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 12.75.1

* `[terminal]` Improved `AlwaysYes` flag handling

### 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_)
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.75.0"
const VERSION = "12.75.1"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
12 changes: 8 additions & 4 deletions terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,20 @@ 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 {
defaultAnswer = defaultAnswers[0]
}

if AlwaysYes {
if title != "" {
fmtc.Println(TitleColorTag + getAnswerTitle(title, defaultAnswer) + "{!}")
}
fmtc.Println(Prompt + "y")
return true, nil
}

for {
answer, err := readUserInput(
getAnswerTitle(title, defaultAnswer), false, false,
Expand Down

0 comments on commit 52086c7

Please sign in to comment.