// Copyright 2025 WIT.COM Inc Licensed GPL 3.0 package forgepb import ( "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) /* better syntax from gin Default returns an Engine instance with the Logger and Recovery middleware already attached. func Default(opts ...OptionFunc) *Engine { engine := New() engine.Use(Logger(), Recovery()) return engine.With(opts...) } */ func Init() (*Forge, error) { cfg, err := loadStdConfig() // will also handle new users return initFromConfig(cfg), err } func InitByAppname(argname string) *Forge { cfg := NewForgeConfigs() err := cfg.loadConfig() if err != nil { log.Info("ConfigLoad() error. make a default config here?", err) } return initFromConfig(cfg) } func InitByFullpath(filename string) *Forge { cfg := NewForgeConfigs() err := config.LoadFile(cfg, filename) if err != nil { log.Info("forge load config err", err) } return initFromConfig(cfg) } func initFromConfig(cfg *ForgeConfigs) *Forge { if cfg == nil { log.Info("forge config was == nil") } f := new(Forge) f.Config = cfg f.Config.loadConfig() // todo: play with these / determine good values based on user's machine if cobol.Int(config.Get("RillX")) == 0 { config.Set("RillX", "10") config.Save() } if cobol.Int(config.Get("RillY")) == 0 { config.Set("RillY", "20") config.Save() } // create an initial repos.pb file // panic() here? // warning? // (probably not. it's just the repos.pb cache file f.Repos = gitpb.NewRepos() err := f.Repos.CacheLoad() // loads the file from ~/.cache/forge/repos.pb if err == nil { log.Printf("forge loaded %s file with len(%d) repos\n", f.Repos.Filename, f.Repos.Len()) } else { log.Printf("forge failed to load %s file with len(%d) repos err=(%v)\n", f.Repos.Filename, f.Repos.Len(), err) panic("failed to load repos.pb") } return f } func (f *Forge) SetConfigSave(b bool) { config.SetChanged("forge", b) } // saves the config if there have been changes func (f *Forge) Close() error { if err := f.ConfigSave(); err != nil { return err } if f.Repos != nil { if config.HasChanged("repos") { if err := f.Repos.Save(); err != nil { log.Info("forge.Repos.ConfigSave() error", err) return err } } } return nil }