From bc35aece9b9ce370f1f388b10dd46a180aed4351 Mon Sep 17 00:00:00 2001 From: eater <=@eater.me> Date: Mon, 5 Aug 2019 23:11:34 +0200 Subject: [PATCH] Fix bugs --- config.go | 6 ++++++ examples/service.toml | 4 ++-- zerooo/cmd/init.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index a43987d..830db0f 100644 --- a/config.go +++ b/config.go @@ -27,11 +27,17 @@ func LoadConfig(path string) (*Config, error) { } func CreateConfig(path string, cfg *Config) { + err := os.MkdirAll(filepath.Dir(path), 0755) + Check(err, "Failed to make directories for %q, err: %s", path, err) conf, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644) Check(err, "Couldn't open %q, err: %s", path, err) encoder := toml.NewEncoder(conf) log.Printf("ZeroooConfig: %#v", cfg) err = encoder.Encode(cfg) + if cfg.Zerooo.Location == "" { + cfg.Zerooo.Location = "/etc/zerooo" + } + if cfg.Zerooo.Location[0] != '/' { cfg.Zerooo.Location = filepath.Join(filepath.Dir(path), cfg.Zerooo.Location) } diff --git a/examples/service.toml b/examples/service.toml index 9e6ac95..14e3483 100644 --- a/examples/service.toml +++ b/examples/service.toml @@ -1,3 +1,3 @@ [zerooo] -location = "/etc/zerooo" -endpoint = "https://zer.ooo" + location = "/etc/zerooo" + endpoint = "https://zer.ooo" diff --git a/zerooo/cmd/init.go b/zerooo/cmd/init.go index 8cdbb0b..f733ac2 100644 --- a/zerooo/cmd/init.go +++ b/zerooo/cmd/init.go @@ -26,7 +26,7 @@ var initCmd = &cobra.Command{ } if (cmd.Flag("location").Changed) { - if location[0] != '/' { + if len(location) > 0 && location[0] != '/' { cwd, err := os.Getwd() service.Check(err, "Can't get current working directory, err: %s", err) location = filepath.Join(cwd, location)