minor
This commit is contained in:
parent
6d4a1be367
commit
5633f4204d
24
config.go
24
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue