summaryrefslogtreecommitdiff
path: root/util/autoport
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2024-05-13 17:35:38 +0200
committerFelix Held <felix-coreboot@felixheld.de>2024-06-17 14:28:28 +0000
commitd15a49b06927016e2a55e9d2c7bb1f5a2321936d (patch)
treee356206936ca71e91c07541e35950f7970fdab8a /util/autoport
parent906099401496ab249edc2aa1691390e4c0e875fe (diff)
util/autoport: Factor out yes/no prompt handling
In preparation for introducing other yes/no prompts, factor out the logic into a common function. Change-Id: Iff1f0c6c665a5352013122fb791121a116c434f3 Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/82402 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'util/autoport')
-rw-r--r--util/autoport/log_maker.go36
1 files changed, 29 insertions, 7 deletions
diff --git a/util/autoport/log_maker.go b/util/autoport/log_maker.go
index 2a524d387a..5ca8284c29 100644
--- a/util/autoport/log_maker.go
+++ b/util/autoport/log_maker.go
@@ -75,6 +75,31 @@ func PromptUser(prompt string, opts []string) (match string, err error) {
return
}
+func AppendYesNo(yesFirst bool, yeah []string, nope []string) []string {
+ if yesFirst {
+ return append(yeah, nope...)
+ } else {
+ return append(nope, yeah...)
+ }
+}
+
+func PromptUserBool(prompt string, fallback bool) bool {
+ yeah := []string{"y", "yes"}
+ nope := []string{"n", "no"}
+
+ opt, err := PromptUser(prompt, AppendYesNo(fallback, yeah, nope))
+ if err != nil {
+ // Continue even if there is an error
+ return fallback
+ }
+ for _, val := range yeah {
+ if opt == val {
+ return true
+ }
+ }
+ return false
+}
+
func MakeHDALogs(outDir string, cardName string) {
SysDir := "/sys/class/sound/" + cardName + "/"
files, _ := ioutil.ReadDir(SysDir)
@@ -119,16 +144,13 @@ func MakeLogs(outDir string) {
RunAndSave(outDir+"/dmidecode.log", "dmidecode")
RunAndSave(outDir+"/acpidump.log", "acpidump")
- inteltoolArgs := "-a"
- opt, err := PromptUser("WARNING: The following tool MAY cause your system to hang when it attempts "+
+ probeGFX := PromptUserBool("WARNING: The following tool MAY cause your system to hang when it attempts "+
"to probe for graphics registers. Having the graphics registers will help create a better port. "+
"Should autoport probe these registers?",
- []string{"y", "yes", "n", "no"})
-
- // Continue even if there is an error
+ true)
- switch opt {
- case "y", "yes":
+ inteltoolArgs := "-a"
+ if probeGFX {
inteltoolArgs += "f"
}