package main import ( "flag" "fmt" "git.burkey.co/eburk/epochcli/pkg/epoch" "log" "os" "os/exec" "strings" ) func main() { outOfDate, err := needUpdate() if err != nil { log.Fatal(err) } if outOfDate { fmt.Println("There is a new version of epochcli, you must update before running") os.Exit(1) } var ( helpFlag bool updateOnlyFlag bool forceFlag bool rerunConfig bool ) flag.BoolVar(&helpFlag, "h", false, "Print help") flag.BoolVar(&forceFlag, "f", false, "Forces epochcli to update files even if they match the current version") flag.BoolVar(&updateOnlyFlag, "u", false, "Ignore EnableLauncher setting in config and only runs an update. Does nothing if EnableLauncher is false") flag.BoolVar(&rerunConfig, "c", false, "Runs config configuration step. Overrides the config file") flag.Parse() if helpFlag { flag.CommandLine.SetOutput(os.Stdout) fmt.Println("Epochcli Help:") flag.PrintDefaults() os.Exit(0) } config, err := setupConfig(rerunConfig) if err != nil { log.Fatal(err) } if config.WowDir == defaultWowPath { log.Fatalf("WowDir in %s is still the default setting, exiting", cfgPath) } stats, err := epoch.DownloadUpdate(config.WowDir, forceFlag, config.RemoveUnknownPatches) if err != nil { log.Fatal(err) } fmt.Printf("%d files updated\n\n", stats.Updated) if stats.Current > 0 { fmt.Printf("%d files are already up to date\n\n", stats.Current) } if configRun { fmt.Println("Configuration complete!") os.Exit(0) } if updateOnlyFlag { os.Exit(0) } if config.EnableLauncher { if config.LaunchCmd == defaultLaunchCmd { log.Fatalf("LaunchCmd in %s is still the default setting, exiting\n", cfgPath) } fmt.Println("Starting Epoch...") var cmd = strings.Split(config.LaunchCmd, " ") ex := exec.Command(cmd[0], cmd[1:]...) cmdStr := strings.Join(cmd, " ") if config.WinePrefix != "" { prefix := fmt.Sprintf("WINEPREFIX=%s", config.WinePrefix) newEnv := append(os.Environ(), prefix) ex.Env = newEnv cmdStr = prefix + " " + cmdStr } fmt.Println("Running command:", cmdStr) err = ex.Run() if err != nil { log.Fatal(err) } } }