create config if it does not exist

This commit is contained in:
Jesse Duffield 2019-06-29 08:55:03 +10:00
parent b9bf469695
commit 02753cee61

View file

@ -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
}