cleanup prompting

This commit is contained in:
2025-07-04 06:10:25 -07:00
parent 4e78277f99
commit 7dd915b060

View File

@ -46,52 +46,37 @@ func setupConfig(rerun bool) (*Config, error) {
} }
newConfig.WowDir = strings.TrimSpace(s) newConfig.WowDir = strings.TrimSpace(s)
for { p, err := promptYesNo(fmt.Sprintf("Do you want to use epochcli to launch Wow? Select No if you plan on using a launcher tool like Lutris (y/n): "))
fmt.Printf("Do you want to use epochcli to launch Wow? Select No if you plan on using a launcher tool like Lutris (y/n): ") if err != nil {
_, err = fmt.Scanf("%s", &s) return nil, err
if err != nil { }
return nil, fmt.Errorf("unable to read input: %v", err) if p {
} newConfig.EnableLauncher = true
s = strings.TrimSpace(s)
if s == "y" || s == "Y" { if runtime.GOOS == "windows" {
newConfig.EnableLauncher = true newConfig.LaunchCmd = path.Join(newConfig.WowDir, "Project-Epoch.exe")
exePath, err := os.Executable()
if err != nil {
return nil, fmt.Errorf("unable to create desktop shortcut: %v", err)
}
err = makeLink(exePath, path.Join(home, "Desktop", "Project-Epoch.lnk"))
if err != nil {
return nil, fmt.Errorf("unable to create desktop shortcut: %v", err)
}
} else {
fmt.Println("Enter your launch command to start Wow below. If you would rather configure this later in the configuration file, just press Enter")
fmt.Printf("> ")
if runtime.GOOS == "windows" { _, err = fmt.Scanf("%s", &s)
newConfig.LaunchCmd = path.Join(newConfig.WowDir, "Project-Epoch.exe") if err != nil {
exePath, err := os.Executable() return nil, fmt.Errorf("unable to read input: %v", err)
if err != nil { }
fmt.Println("unable to create desktop shortcut: ", err) s = strings.TrimSpace(s)
break
}
err = makeLink(exePath, path.Join(home, "Desktop", "Project-Epoch.lnk"))
if err != nil {
fmt.Println("unable to create desktop shortcut: ", err)
}
break
} else {
fmt.Println("Enter your launch command to start Wow below. If you would rather configure this later in the configuration file, just press Enter")
fmt.Printf("> ")
_, err = fmt.Scanf("%s", &s) if s != "" {
if err != nil { newConfig.LaunchCmd = s
return nil, fmt.Errorf("unable to read input: %v", err)
}
s = strings.TrimSpace(s)
if s != "" {
newConfig.LaunchCmd = s
}
break
} }
} }
if s == "n" || s == "N" {
break
}
fmt.Println("Please enter a valid value of either 'y' or 'n'")
} }
err = os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755) err = os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
@ -120,3 +105,24 @@ func setupConfig(rerun bool) (*Config, error) {
return &newConfig, nil return &newConfig, nil
} }
func promptYesNo(prompt string) (bool, error) {
var s string
for {
fmt.Print(prompt)
_, err := fmt.Scanf("%s", &s)
if err != nil {
return false, fmt.Errorf("unable to read input: %v", err)
}
s := strings.TrimSpace(s)
if s == "y" || s == "Y" {
return true, nil
}
if s == "n" || s == "N" {
return false, nil
}
fmt.Println("Please enter a valid value of either 'y' or 'n'")
}
}