diff options
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 54 |
1 files changed, 52 insertions, 2 deletions
@@ -3,7 +3,13 @@ package forgepb import ( + "errors" + "os" + "os/user" + "path/filepath" + "go.wit.com/lib/config" + "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/prep" "go.wit.com/log" ) @@ -65,8 +71,9 @@ func (cfg *ForgeConfigs) DumpENV() { if cfg.GoWork { log.Infof("CfgPB.GoWork = %v\n", cfg.GoWork) } - log.Infof("CfgPB.Mode = %s\n", cfg.Mode) - log.Infof("CfgPB.PatchDir = %s #deprecate\n", cfg.PatchDir) + if cfg.Mode != ForgeMode_UNKNOWN { + log.Infof("CfgPB.Mode = %s\n", cfg.Mode) + } // log.Infof("CfgPB.Hostname=%s\n", cfg.Hostname) } @@ -80,3 +87,46 @@ func (cfg *ForgeConfigs) DumpENV() { f.SetConfigSave(true) } */ + +func loadStdConfig() *ForgeConfigs { + cfg := NewForgeConfigs() + err := config.ConfigLoad(cfg, "forge", "forge") + + if err == nil { + return cfg + } + + if errors.Is(err, os.ErrNotExist) { + log.Info("no files existed err=", err) + } else if errors.Is(err, config.ErrEmpty) { + log.Info("files were blank err=", err) + } else if errors.Is(err, config.ErrMarshal) { + log.Info("files existed and could not be Marshalled() err=", err) + } else { + log.Info("some other bad problem err=", err) + } + + // this is probably the users first time + // TODO: check if ./config/forge exists, then something else went wrong... + + usr, _ := user.Current() + cfg.Username = usr.Username + + homeDir, _ := os.UserHomeDir() + + cfgdir := filepath.Join(homeDir, ".config/forge") + os.MkdirAll(cfgdir, os.ModePerm) + + cfg.HomeDir = cfgdir + cfg.ReposDir = filepath.Join(homeDir, "go/src") // todo: check working directory + cfg.ReposPB = filepath.Join(cfgdir, "repos.pb") + cfg.PatchPB = filepath.Join(cfgdir, "patches.pb") + cfg.ForgeURL = "http://forge.wit.com/" + + cfg.DumpENV() + if !fhelp.QuestionUser("This is your first time using forge, use these default values?") { + os.Exit(-1) + } + cfg.ConfigSave() + return cfg +} |
