cleanup prompting #1

Merged
eburk merged 1 commits from cleanup into master 2025-07-04 13:29:56 +00:00

View File

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