From 02753cee616f23e0ab29f2a36ddc41911e3d0cd9 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 29 Jun 2019 08:55:03 +1000 Subject: [PATCH] create config if it does not exist --- pkg/config/app_config.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 24d67301..da5e0765 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -2,6 +2,7 @@ package config import ( "io/ioutil" + "os" "path/filepath" "time" @@ -293,7 +294,21 @@ func loadUserConfigWithDefaults(configDir string) (*UserConfig, error) { } func loadUserConfig(configDir string, base *UserConfig) (*UserConfig, error) { - content, err := ioutil.ReadFile(filepath.Join(configDir, "config.yml")) + fileName := filepath.Join(configDir, "config.yml") + + if _, err := os.Stat(fileName); err != nil { + if os.IsNotExist(err) { + file, err := os.Create(fileName) + if err != nil { + return nil, err + } + file.Close() + } else { + return nil, err + } + } + + content, err := ioutil.ReadFile(fileName) if err != nil { return nil, err }