mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-10-27 05:20:14 -04:00
107 lines
2.2 KiB
Go
107 lines
2.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/mrusme/gobbs/config"
|
|
"github.com/mrusme/gobbs/system"
|
|
"github.com/mrusme/gobbs/ui"
|
|
"github.com/mrusme/gobbs/ui/ctx"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var LOG *zap.SugaredLogger
|
|
var CFG config.Config
|
|
|
|
func init() {
|
|
cobra.OnInitialize(load)
|
|
rootCmd.
|
|
PersistentFlags().
|
|
Bool(
|
|
"debug",
|
|
false,
|
|
"Debug output",
|
|
)
|
|
viper.BindPFlag(
|
|
"debug",
|
|
rootCmd.PersistentFlags().Lookup("debug"),
|
|
)
|
|
}
|
|
|
|
func load() {
|
|
var err error
|
|
var logger *zap.Logger
|
|
|
|
CFG, err = config.Load()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if CFG.Debug == "true" {
|
|
logger, _ = zap.NewDevelopment()
|
|
} else {
|
|
logger, _ = zap.NewProduction()
|
|
}
|
|
defer logger.Sync()
|
|
LOG = logger.Sugar()
|
|
}
|
|
|
|
func loadSystems(c *ctx.Ctx) []error {
|
|
var errs []error
|
|
|
|
for _, sysCfg := range c.Config.Systems {
|
|
sys, err := system.New(sysCfg.Type, &sysCfg.Config, LOG)
|
|
if err != nil {
|
|
c.Logger.Errorf("error loading system: %s", err)
|
|
errs = append(errs, err)
|
|
} else {
|
|
c.Logger.Debugln("loaded system")
|
|
}
|
|
|
|
c.AddSystem(&sys)
|
|
}
|
|
|
|
return errs
|
|
}
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "gobbs",
|
|
SuggestFor: []string{"bbs", "discourse", "lemmy"},
|
|
Short: "Gobbs, the bulletin board system TUI",
|
|
Long: "Gobbs is a bulletin board system (BBS) text user interface written " +
|
|
"in Go, supporting Discourse and Lemmy.\n" +
|
|
"More info available on https://xn--gckvb8fzb.com/projects/gobbs",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
var err error
|
|
|
|
c := ctx.New(&CFG, LOG)
|
|
_ = loadSystems(&c) // TODO: Handle errs
|
|
|
|
// a, _ := aggregator.New(&c)
|
|
// posts, errs := a.ListPosts()
|
|
// // posts, err := (*c.Systems[0]).ListPosts()
|
|
// fmt.Println("-----------------------")
|
|
// fmt.Printf("%v\n", posts)
|
|
// fmt.Printf("%v\n", errs)
|
|
//
|
|
// // err = s(*c.Systems[0]).LoadPost(&posts[4])
|
|
// err := a.LoadPost(&posts[4])
|
|
// fmt.Printf("%v\n", posts[4].Replies[2])
|
|
// fmt.Printf("%v\n", err)
|
|
// os.Exit(0)
|
|
|
|
tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen())
|
|
err = tui.Start()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
},
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
// LOG.Errorln(err)
|
|
}
|
|
}
|