create an empty config file if it does not already exist
This commit is contained in:
parent
70fa81c663
commit
31f1cfaa4e
8
types.go
8
types.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kevinschoon/pomo/libnotify"
|
"github.com/kevinschoon/pomo/libnotify"
|
||||||
|
@ -91,6 +92,13 @@ func (c *Config) UnmarshalJSON(raw []byte) error {
|
||||||
func NewConfig(path string) (*Config, error) {
|
func NewConfig(path string) (*Config, error) {
|
||||||
raw, err := ioutil.ReadFile(path)
|
raw, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
config := &Config{
|
config := &Config{
|
||||||
|
|
Loading…
Reference in New Issue