From d15a49b06927016e2a55e9d2c7bb1f5a2321936d Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Mon, 13 May 2024 17:35:38 +0200 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/82402 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- util/autoport/log_maker.go | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'util/autoport') 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" } -- cgit v1.2.3