aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 19:14:53 +0200
committerTeddy Wing2017-06-03 19:14:53 +0200
commit557d6fda17c5368d7f76e823bca00335afb7ee0c (patch)
tree886852001d4e62392b913fda5f2e7baa46e9becc
parent12ef5ad5d62297af90e7a4c819bd5c2835a00a05 (diff)
downloadtimetasker-557d6fda17c5368d7f76e823bca00335afb7ee0c.tar.bz2
MaybeWriteConfig(): Write an empty config file
If no existing config file is found, write a sample config file to XDG_CONFIG_HOME/timetasker/config.toml.
-rw-r--r--config.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/config.go b/config.go
index 21f0406..f26e560 100644
--- a/config.go
+++ b/config.go
@@ -1,13 +1,32 @@
package main
import (
+ "io/ioutil"
"os"
"path/filepath"
"github.com/goulash/xdg"
)
-func MaybeWriteConfig() {
+const emptyConfig = `[auth]
+username = ""
+password_cmd = ""
+
+
+[profile]
+person_id = # ADD PERSON ID
+
+
+[projects.example]
+client = # ADD CLIENT ID
+project = # ADD PROJECT ID
+module = # ADD MODULE ID
+task = 0
+work_type = # ADD WORK TYPE ID
+billable = true
+`
+
+func MaybeWriteConfig() error {
path := xdg.FindConfig("timetasker/config.toml")
if path == "" {
@@ -15,5 +34,13 @@ func MaybeWriteConfig() {
if _, err := os.Stat(path); os.IsNotExist(err) {
os.Mkdir(path, 0700)
}
+
+ config_path := filepath.Join(path, "config.toml")
+ err := ioutil.WriteFile(config_path, []byte(emptyConfig), 0644)
+ if err != nil {
+ return err
+ }
}
+
+ return nil
}