Skip to content

Commit

Permalink
feat: automatically select option when only one exists
Browse files Browse the repository at this point in the history
Fixes #78
  • Loading branch information
metacosm committed Feb 27, 2020
1 parent c9d31d7 commit 53dac23
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,15 @@ func SelectFromOtherErrorMessage(msg, wrong string) string {
}

func SelectOrCheckExisting(parameterValue *string, capitalizedParameterName string, validValues []string, validator func() bool) {
lowerCaseParameterName := strings.ToLower(capitalizedParameterName)
if len(*parameterValue) == 0 {
if len(validValues) == 1 {
*parameterValue = validValues[0]
OutputSelection("Automatically selected only available "+lowerCaseParameterName, *parameterValue)
return
}
*parameterValue = Select(capitalizedParameterName, validValues)
} else {
lowerCaseParameterName := strings.ToLower(capitalizedParameterName)
if !validator() {
s := SelectFromOtherErrorMessage("Unknown "+lowerCaseParameterName, *parameterValue)
Select(s, validValues)
Expand Down

0 comments on commit 53dac23

Please sign in to comment.