cleanup prompting

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

View File

@ -46,29 +46,23 @@ 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): ")
_, err = fmt.Scanf("%s", &s)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read input: %v", err) return nil, err
} }
s = strings.TrimSpace(s) if p {
if s == "y" || s == "Y" {
newConfig.EnableLauncher = true newConfig.EnableLauncher = true
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
newConfig.LaunchCmd = path.Join(newConfig.WowDir, "Project-Epoch.exe") newConfig.LaunchCmd = path.Join(newConfig.WowDir, "Project-Epoch.exe")
exePath, err := os.Executable() exePath, err := os.Executable()
if err != nil { if err != nil {
fmt.Println("unable to create desktop shortcut: ", err) return nil, fmt.Errorf("unable to create desktop shortcut: %v", err)
break
} }
err = makeLink(exePath, path.Join(home, "Desktop", "Project-Epoch.lnk")) err = makeLink(exePath, path.Join(home, "Desktop", "Project-Epoch.lnk"))
if err != nil { if err != nil {
fmt.Println("unable to create desktop shortcut: ", err) return nil, fmt.Errorf("unable to create desktop shortcut: %v", err)
} }
break
} else { } 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.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("> ") fmt.Printf("> ")
@ -82,18 +76,9 @@ func setupConfig(rerun bool) (*Config, error) {
if s != "" { if s != "" {
newConfig.LaunchCmd = 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)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to create config directory: %v", err) return nil, fmt.Errorf("unable to create config directory: %v", err)
@ -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'")
}
}