2022-12-28 22:22:36 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
2022-12-29 14:34:51 -05:00
|
|
|
"github.com/mrusme/gobbs/config"
|
2022-12-28 22:22:36 -05:00
|
|
|
"github.com/mrusme/gobbs/system"
|
|
|
|
"github.com/mrusme/gobbs/ui"
|
|
|
|
"github.com/mrusme/gobbs/ui/ctx"
|
2022-12-29 14:34:51 -05:00
|
|
|
"go.uber.org/zap"
|
2022-12-28 22:22:36 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-12-29 14:34:51 -05:00
|
|
|
var logger *zap.Logger
|
|
|
|
var sugar *zap.SugaredLogger
|
2022-12-28 22:22:36 -05:00
|
|
|
|
2022-12-29 14:34:51 -05:00
|
|
|
cfg, err := config.Load()
|
2022-12-28 22:22:36 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-12-29 14:34:51 -05:00
|
|
|
if cfg.Debug == "true" {
|
|
|
|
logger, _ = zap.NewDevelopment()
|
|
|
|
} else {
|
|
|
|
logger, _ = zap.NewProduction()
|
|
|
|
}
|
|
|
|
defer logger.Sync()
|
|
|
|
sugar = logger.Sugar()
|
|
|
|
|
|
|
|
c := ctx.New(&cfg, sugar)
|
|
|
|
_ = loadSystems(&c) // TODO: Handle errs
|
2022-12-28 22:22:36 -05:00
|
|
|
|
|
|
|
tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen())
|
|
|
|
err = tui.Start()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2022-12-29 14:34:51 -05:00
|
|
|
|
|
|
|
func loadSystems(c *ctx.Ctx) []error {
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
for _, sysCfg := range c.Config.Systems {
|
|
|
|
sys, err := system.New(sysCfg.Type, &sysCfg.Config)
|
|
|
|
if err != nil {
|
|
|
|
c.Logger.Errorf("error loading system: %s", err)
|
|
|
|
errs = append(errs, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.AddSystem(&sys)
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|