From 31f1cfaa4e4c8fdf7eff9983ddac7421417ed5e5 Mon Sep 17 00:00:00 2001 From: Kevin Schoon Date: Sun, 28 Jan 2018 19:09:25 -0500 Subject: [PATCH] create an empty config file if it does not already exist --- types.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types.go b/types.go index 66fb76c..8af6b13 100644 --- a/types.go +++ b/types.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/fatih/color" "io/ioutil" + "os" "time" "github.com/kevinschoon/pomo/libnotify" @@ -91,6 +92,13 @@ func (c *Config) UnmarshalJSON(raw []byte) error { func NewConfig(path string) (*Config, error) { raw, err := ioutil.ReadFile(path) if err != nil { + // Create an empty config file + // if it does not already exist. + if os.IsNotExist(err) { + raw, _ := json.Marshal(map[string]*color.Color{}) + ioutil.WriteFile(path, raw, 0644) + return NewConfig(path) + } return nil, err } config := &Config{