aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2017-01-16 17:35:36 -0500
committerMitch Riedstra <mitch@riedstra.us>2017-01-16 17:35:36 -0500
commit5078083aa80279724f834305ca52946c7114b2ca (patch)
tree4022334cc6bf251a9c8bc10e46e16bb0a87a37c3 /config
parent6074026163c8d8e03c5f4a3b72067328e1ab78c5 (diff)
downloadsteam-export-5078083aa80279724f834305ca52946c7114b2ca.tar.gz
steam-export-5078083aa80279724f834305ca52946c7114b2ca.tar.xz
Pull default configuration into the application, add an edit command
Diffstat (limited to 'config')
-rw-r--r--config/config.go66
-rw-r--r--config/config_unix.go22
-rw-r--r--config/config_windows.go22
3 files changed, 102 insertions, 8 deletions
diff --git a/config/config.go b/config/config.go
index 19a79c4..c63a0bc 100644
--- a/config/config.go
+++ b/config/config.go
@@ -4,10 +4,8 @@ package config
import (
"gopkg.in/yaml.v2"
"io/ioutil"
-)
-
-var (
- defaultConfig string = "config.yml"
+ "os"
+ "os/exec"
)
type Config struct {
@@ -16,6 +14,8 @@ type Config struct {
Listen string
}
+var configFilename string = "steam-export.yml"
+
// By default it reads 'config.yml' in the current directory
func LoadConfig() (*Config, error) {
c := &Config{}
@@ -23,10 +23,6 @@ func LoadConfig() (*Config, error) {
return c, err
}
-func (c *Config) ReadDefaultConfig() error {
- return c.ReadConfig(defaultConfig)
-}
-
func (c *Config) ReadConfig(cfg string) error {
contents, err := ioutil.ReadFile(cfg)
if err != nil {
@@ -34,3 +30,57 @@ func (c *Config) ReadConfig(cfg string) error {
}
return yaml.Unmarshal([]byte(contents), c)
}
+
+func checkConfigFile(cf string) error {
+ // Check if our config file exists, or create it
+ if _, err := os.Stat(cf); err != nil {
+ if f, err := os.Create(cf); err != nil {
+ return err
+ } else {
+ f.WriteString(`
+---
+listen: 0.0.0.0:9413
+# Repositories that you want to expose on the web server
+SteamRepositories:
+ # We're ideally looking for the full path to the steamapps folder
+ # On windows you're going to escape the slashes
+ - "C:\\Program Files (x86)\\Steam\\steamapps"
+ # - "/usr/mitch/SteamGames/steamapps"
+
+# This defaults to:
+# Only change this if your default Steam library is different than the Steam default
+# DefaultRepository: "/usr/mitch/SteamGames/steamapps"
+# DefaultRepository: "Z:\\SteamGames\\steamapps"
+`)
+ f.Close()
+ }
+ }
+ return nil
+}
+
+func (c *Config) ReadDefaultConfig() error {
+ if err := c.ReadConfig(configFilename); err != nil {
+ if err = checkConfigFile(fn); err != nil {
+ return err
+ }
+ return c.ReadConfig(fn)
+ }
+ return nil
+}
+
+func EditDefaultConfig(e string) error {
+ if e != "" {
+ editor = e
+ }
+
+ if _, err := os.Stat(configFilename); err != nil {
+ if _, err := os.Stat(fn); err != nil {
+ return err
+ }
+ c := exec.Command(editor, fn)
+ return c.Run()
+ }
+ cmd := exec.Command(editor, configFilename)
+ return cmd.Run()
+
+}
diff --git a/config/config_unix.go b/config/config_unix.go
new file mode 100644
index 0000000..8f77235
--- /dev/null
+++ b/config/config_unix.go
@@ -0,0 +1,22 @@
+// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+
+package config
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+var (
+ editor string = setEditor()
+ fn string = filepath.Join(os.Getenv("HOME"), "."+configFilename)
+)
+
+func setEditor() string {
+ e := os.Getenv("EDITOR")
+ if e == "" {
+ return "vi"
+ }
+ return e
+}
diff --git a/config/config_windows.go b/config/config_windows.go
new file mode 100644
index 0000000..39b6b6c
--- /dev/null
+++ b/config/config_windows.go
@@ -0,0 +1,22 @@
+// +build windows
+
+package config
+
+import (
+ "os"
+ // "os/exec"
+ "path/filepath"
+)
+
+var (
+ editor string = setEditor()
+ fn string = filepath.Join(os.Getenv("LOCALAPPDATA"), configFilename)
+)
+
+func setEditor() string {
+ e := os.Getenv("EDITOR")
+ if e == "" {
+ return `C:\Program Files\Windows NT\Accessories\wordpad.exe`
+ }
+ return e
+}