// Copyright 2025 WIT.COM Inc Licensed GPL 3.0 package forgepb import ( "errors" "os" "go.wit.com/lib/ENV" "go.wit.com/lib/config" "go.wit.com/log" ) func (f *Forge) SetMode(newmode ForgeMode) error { if f.mode == newmode { // nothing changed return nil } f.mode = newmode err := ENV.Set("mode", newmode.String()) if err != nil { panic("ENV.Set() doesn't work") } err = ENV.Save() if err != nil { panic("ENV.Save() doesn't work") } return err } func loadStdConfig() (*ForgeConfigs, error) { cfg := NewForgeConfigs() err := cfg.loadConfig() // todo: do something here with this error? // right now, handled in forge // todo: move the code from forge here 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 if err == nil { // do nothing. probably shoulda started with this } else { log.Info("some other bad problem err=", err) } return cfg, 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) }