aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--config-example.yml9
-rw-r--r--config/config.go66
-rw-r--r--config/config_unix.go22
-rw-r--r--config/config_windows.go22
-rw-r--r--steam-export-cli.go12
6 files changed, 119 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index db36e14..af43141 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-config.yml
+steam-export.yml
bin
test*.go
*.tar
diff --git a/config-example.yml b/config-example.yml
index 01e24e8..fd81fb7 100644
--- a/config-example.yml
+++ b/config-example.yml
@@ -1,14 +1,13 @@
---
listen: 0.0.0.0:9413
# Repositories that you want to expose on the web server
-SteamRepositories:
+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"
-# optional
# This defaults to:
-# "C:\\Program Files (x86)\\Steam\\steamapps"
-#if not set. This doesn't have to be listed in the repository list above
-DefaultRepository: "/usr/mitch/SteamGames/steamapps"
+# Only change this if your default Steam library is different than the Steam default
+# DefaultRepository: "/usr/mitch/SteamGames/steamapps"
+# DefaultRepository: "Z:\\SteamGames\\steamapps"
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
+}
diff --git a/steam-export-cli.go b/steam-export-cli.go
index e738fa9..3b9d607 100644
--- a/steam-export-cli.go
+++ b/steam-export-cli.go
@@ -30,6 +30,8 @@ func parseArgs(args []string) error {
return extractGame(aa)
case "delete":
return deleteGame(aa)
+ case "edit-config":
+ return editConfig(aa)
default:
printHelp()
}
@@ -47,10 +49,20 @@ Subcommands:
extract -l $steam_library -f $input_file
delete -l $steam_library -g $game_index
server -c $config_file -l $steam_library -L $listen_addr
+ edit-config [ -e $editor ]
`)
}
+func editConfig(args []string) error {
+ fl := flag.NewFlagSet("edit-config", errorHandling)
+ e := fl.String("e", "", "Editor to invoke")
+ if err := fl.Parse(args); err != nil {
+ return err
+ }
+ return config.EditDefaultConfig(*e)
+}
+
func listGames(args []string) error {
fl := flag.NewFlagSet("list", errorHandling)
lib := fl.String("l", steam.DefaultLib,