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>
This commit is contained in:
Angel Pons
2024-05-13 17:35:38 +02:00
committed by Felix Held
parent 9060994014
commit d15a49b069

View File

@ -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"})
true)
// Continue even if there is an error
switch opt {
case "y", "yes":
inteltoolArgs := "-a"
if probeGFX {
inteltoolArgs += "f"
}