diff options
author | Teddy Wing | 2017-06-03 18:55:51 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-03 18:55:51 +0200 |
commit | 12ef5ad5d62297af90e7a4c819bd5c2835a00a05 (patch) | |
tree | 2464926a405cd6963b446973a50c93bd7c011e32 /config.go | |
parent | b0858ffc7b79f3baf6d1f15962ab90a35275707e (diff) | |
download | timetasker-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.
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 19 |
1 files changed, 19 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) + } + } +} |