summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/config.go b/config.go
index ceee616..23e0435 100644
--- a/config.go
+++ b/config.go
@@ -40,6 +40,11 @@ func (m *Repos) ConfigSave() error {
}
func (m *Repos) ConfigLoad() error {
+ if os.Getenv("FORGE_HOME") == "" {
+ homeDir, _ := os.UserHomeDir()
+ fullpath := filepath.Join(homeDir, ".config/forge")
+ os.Setenv("FORGE_HOME", fullpath)
+ }
var data []byte
var err error
if m == nil {
@@ -50,7 +55,6 @@ func (m *Repos) ConfigLoad() error {
// something went wrong loading the file
return err
}
-
if data != nil {
// this means the forge.pb file exists and was read
if len(data) == 0 {
@@ -61,6 +65,7 @@ func (m *Repos) ConfigLoad() error {
log.Warn("broken forge.pb config file")
return err
}
+ log.Info("config load found", len(m.Repos), "repos")
return nil
}
@@ -80,6 +85,27 @@ func (m *Repos) ConfigLoad() error {
log.Warn("broken forge.text config file")
return err
}
+ log.Info("config load found", len(m.Repos), "repos")
+ return nil
+ }
+
+ // forge.text doesn't exist. try forge.json
+ // this lets the user hand edit the config
+ if data, err = loadFile("forge.json"); err != nil {
+ // something went wrong loading the file
+ return err
+ }
+
+ if data != nil {
+ // this means the forge.text file exists and was read
+ if len(data) == 0 {
+ // todo: error out if the file is empty?
+ }
+ if err = m.UnmarshalJSON(data); err != nil {
+ log.Warn("broken forge.json config file")
+ return err
+ }
+ log.Info("config load found", len(m.Repos), "repos")
return nil
}