From 5633f4204d6bfbce643f1fc6f74f988446c2b8c0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 21 Nov 2024 10:27:40 -0600 Subject: [PATCH] minor --- config.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 2fe52f6..7b28496 100644 --- a/config.go +++ b/config.go @@ -13,6 +13,7 @@ import ( // writes out the cluster information it seperate files // to make it humanly possible to hand edit things as needed +// write to ~/.config/forge/ unless ENV{FORGE_HOME} is set func (m *Repos) ConfigSave() error { if os.Getenv("FORGE_HOME") == "" { homeDir, _ := os.UserHomeDir() @@ -39,7 +40,8 @@ func (m *Repos) ConfigSave() error { return nil } -func (m *Repos) ConfigLoad() error { +// load the ~/.config/forge/ files +func (c *Repos) ConfigLoad() error { if os.Getenv("FORGE_HOME") == "" { homeDir, _ := os.UserHomeDir() fullpath := filepath.Join(homeDir, ".config/forge") @@ -47,8 +49,9 @@ func (m *Repos) ConfigLoad() error { } var data []byte var err error - if m == nil { - return errors.New("It's not safe to run ConfigLoad() on a nil ?") + if c == nil { + // can't safely do c = new(Repo) if c is in a struct from the caller. notsure why + return errors.New("It's not safe to run ConfigLoad() on a nil") } if data, err = loadFile("forge.pb"); err != nil { @@ -61,11 +64,11 @@ func (m *Repos) ConfigLoad() error { // todo: error out if the file is empty? // try forge.text & forge.json? } - if err = m.Unmarshal(data); err != nil { + if err = c.Unmarshal(data); err != nil { log.Warn("broken forge.pb config file") return err } - log.Info("config load found", len(m.Repos), "repos") + log.Info("config load found", len(c.Repos), "repos") return nil } @@ -81,11 +84,11 @@ func (m *Repos) ConfigLoad() error { if len(data) == 0 { // todo: error out if the file is empty? } - if err = m.UnmarshalTEXT(data); err != nil { + if err = c.UnmarshalTEXT(data); err != nil { log.Warn("broken forge.text config file") return err } - log.Info("config load found", len(m.Repos), "repos") + log.Info("config load found", len(c.Repos), "repos") return nil } @@ -101,16 +104,17 @@ func (m *Repos) ConfigLoad() error { if len(data) == 0 { // todo: error out if the file is empty? } - if err = m.UnmarshalJSON(data); err != nil { + if err = c.UnmarshalJSON(data); err != nil { log.Warn("broken forge.json config file") return err } - log.Info("config load found", len(m.Repos), "repos") + log.Info("config load found", len(c.Repos), "repos") return nil } - m.SampleConfig() // first time user. make a template config file + c.SampleConfig() + return nil }