aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 18:55:51 +0200
committerTeddy Wing2017-06-03 18:55:51 +0200
commit12ef5ad5d62297af90e7a4c819bd5c2835a00a05 (patch)
tree2464926a405cd6963b446973a50c93bd7c011e32
parentb0858ffc7b79f3baf6d1f15962ab90a35275707e (diff)
downloadtimetasker-12ef5ad5d62297af90e7a4c819bd5c2835a00a05.tar.bz2
Add `MaybeWriteConfig()`
A new function that will write a new config.toml file to the XDG_CONFIG_HOME directory. Currently it checks to see whether our config file is present. If not and our config directory isn't present, it creates it. Still need to get this to actually write the config file. Also, we won't want to call it by default in main() like we're doing now. Will likely want to hide it behind a `--write-config` flag.
-rw-r--r--config.go19
-rw-r--r--main.go1
2 files changed, 20 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..21f0406
--- /dev/null
+++ b/config.go
@@ -0,0 +1,19 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+
+ "github.com/goulash/xdg"
+)
+
+func MaybeWriteConfig() {
+ path := xdg.FindConfig("timetasker/config.toml")
+
+ if path == "" {
+ path = filepath.Join(xdg.ConfigHome, "timetasker")
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ os.Mkdir(path, 0700)
+ }
+ }
+}
diff --git a/main.go b/main.go
index eaef1fc..0c8a8e9 100644
--- a/main.go
+++ b/main.go
@@ -29,6 +29,7 @@ var config Config
func main() {
var err error
+ MaybeWriteConfig()
loadConfig()
// Parse command line arguments