From 557d6fda17c5368d7f76e823bca00335afb7ee0c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 19:14:53 +0200 Subject: 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. --- config.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'config.go') 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 } -- cgit v1.2.3