aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 19:42:06 +0200
committerTeddy Wing2017-06-03 20:53:14 +0200
commitfa85a708dff621e4d75f19bdbd45bba5947685c0 (patch)
tree947814fce922aee3a7d298c5cca19a063ebbb68c
parent855728d1be71170a80ac4b725553b7ff67e85dc4 (diff)
downloadtimetasker-fa85a708dff621e4d75f19bdbd45bba5947685c0.tar.bz2
config.go: Extract config file paths to functions
Put these constructed paths into reusable functions for easier usage.
-rw-r--r--config.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/config.go b/config.go
index e2d2f94..43f7689 100644
--- a/config.go
+++ b/config.go
@@ -38,16 +38,24 @@ work_type = # ADD WORK TYPE ID
billable = true
`
+func configDir() string {
+ return filepath.Join(xdg.ConfigHome, "timetasker")
+}
+
+func configFile() string {
+ return filepath.Join(configDir(), "config.toml")
+}
+
func maybeWriteConfig() error {
path := xdg.FindConfig("timetasker/config.toml")
if path == "" {
- path = filepath.Join(xdg.ConfigHome, "timetasker")
+ path = configDir()
if _, err := os.Stat(path); os.IsNotExist(err) {
os.Mkdir(path, 0700)
}
- config_path := filepath.Join(path, "config.toml")
+ config_path := configFile()
err := ioutil.WriteFile(config_path, []byte(emptyConfig), 0644)
if err != nil {
return err