summaryrefslogtreecommitdiff
path: root/Load.go
diff options
context:
space:
mode:
Diffstat (limited to 'Load.go')
-rw-r--r--Load.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/Load.go b/Load.go
index f69279e..8a5118f 100644
--- a/Load.go
+++ b/Load.go
@@ -14,18 +14,38 @@ import (
"go.wit.com/lib/ENV"
"go.wit.com/lib/config"
+ "go.wit.com/lib/protobuf/argvpb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func (pb *ForgeConfigs) loadConfig() error {
filename, err := config.LoadByAppName(pb, "forge", "forge")
+ log.Printf("%s loadConfig() about to load Config from %s\n", argvpb.GetAPPNAME(), filename)
if err != nil {
log.Info("couldn't load filename:", filename)
log.Info("forge has not been configured")
panic("config failed to load. make a new/blank forge config here?")
}
ENV.SetGlobal("lib/forgepb", "ForgeCfg", pb.Filename)
+ var changed bool
+ // migrate from the old gopath to "namespace"
+ for fc := range pb.IterAll() {
+ if fc.Namespace != "" {
+ continue
+ }
+ if fc.Namespace != fc.GoPath {
+ fc.Namespace = fc.GoPath
+ changed = true
+ }
+ // todo: deprecate this
+ fc.GoPath = "" // I want to do this but it might be a bad idea at this point
+ }
+ log.Printf("%s loadConfig() loaded Config from %s\n", argvpb.GetAPPNAME(), pb.Filename)
+ if changed {
+ config.SetChanged("forge", true)
+ }
+
// init new config here
return err
}
@@ -58,3 +78,33 @@ func (f *Forge) loadPatchsets() error {
return nil
}
*/
+
+func makeDefaultConfig() (*ForgeConfigs, error) {
+ cfg := NewForgeConfigs()
+ // Get fullpath to ~/.config/forge/forge.text
+ cfg.loadConfig()
+
+ cfg.addSampleConfigs()
+ ENV.PrintTable()
+ var err error
+ if err = cfg.saveVerbose(); err != nil {
+ log.Info("config save error:", err)
+ }
+ return cfg, err
+}
+
+// first time user. add go.wit.com as an example
+func (cfg *ForgeConfigs) addSampleConfigs() {
+ newc := new(ForgeConfig)
+ newc.GoPath = "go.wit.com"
+ newc.Writable = true
+ newc.Directory = true
+ cfg.Append(newc)
+
+ newc = new(ForgeConfig)
+ newc.GoPath = "priv.wit.com/corp"
+ newc.Writable = true
+ newc.Private = true
+ newc.Directory = true
+ cfg.Append(newc)
+}