add ability to launch epoch client
This commit is contained in:
59
config.go
Normal file
59
config.go
Normal file
@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BurntSushi/toml"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
WowDir string
|
||||
LaunchCmd string
|
||||
}
|
||||
|
||||
const (
|
||||
configDirName = "epochcli"
|
||||
configName = "config.toml"
|
||||
)
|
||||
|
||||
var cfgPath string
|
||||
|
||||
func setupConfig() (*Config, error) {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
return nil, fmt.Errorf("$HOME environment variable not set")
|
||||
}
|
||||
|
||||
newConfig := Config{
|
||||
WowDir: defaultWowPath,
|
||||
LaunchCmd: defaultLaunchCmd,
|
||||
}
|
||||
|
||||
cfgPath = filepath.Join(home, ".config", configDirName, configName)
|
||||
|
||||
if _, statErr := os.Stat(cfgPath); os.IsNotExist(statErr) {
|
||||
os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
|
||||
|
||||
file, err := os.Create(cfgPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
encoder := toml.NewEncoder(file)
|
||||
if err = encoder.Encode(newConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Printf("Created new config at %s, edit it before running the launcher again\n", cfgPath)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
_, err := toml.DecodeFile(cfgPath, &newConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &newConfig, nil
|
||||
}
|
Reference in New Issue
Block a user