mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-01-03 14:56:41 -05:00
Implemented connect cmd, migrated code from root
This commit is contained in:
parent
9bdec33795
commit
72b25f8369
70
cmd/connect.go
Normal file
70
cmd/connect.go
Normal file
@ -0,0 +1,70 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/mrusme/gobbs/config"
|
||||
"github.com/mrusme/gobbs/system"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := connectBase()
|
||||
rootCmd.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func connectBase() *cobra.Command {
|
||||
var sysType string = ""
|
||||
var sysURL string = ""
|
||||
var sysConfig map[string]interface{}
|
||||
|
||||
var cmd = &cobra.Command{
|
||||
Use: "connect",
|
||||
Short: "Connect to BBS",
|
||||
Long: "Add a new connection to a BBS.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
sysConfig = make(map[string]interface{})
|
||||
sys, err := system.New(sysType, &sysConfig)
|
||||
if err != nil {
|
||||
LOG.Panicln(err)
|
||||
}
|
||||
|
||||
if err := sys.Connect(sysURL); err != nil {
|
||||
LOG.Panicln(err)
|
||||
}
|
||||
|
||||
CFG.Systems = append(CFG.Systems, config.SystemConfig{
|
||||
Type: sysType,
|
||||
Config: sys.GetConfig(),
|
||||
})
|
||||
if err := CFG.Save(); err != nil {
|
||||
LOG.Panicln(err)
|
||||
}
|
||||
|
||||
LOG.Infoln("Successfully added new connection!")
|
||||
os.Exit(0)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.
|
||||
Flags().
|
||||
StringVar(
|
||||
&sysType,
|
||||
"type",
|
||||
"",
|
||||
"Type of system to connect to (discourse, lemmy)",
|
||||
)
|
||||
cmd.MarkFlagRequired("type")
|
||||
|
||||
cmd.
|
||||
Flags().
|
||||
StringVar(
|
||||
&sysURL,
|
||||
"url",
|
||||
"",
|
||||
"URL of system (e.g. https://www.keebtalk.com)",
|
||||
)
|
||||
cmd.MarkFlagRequired("url")
|
||||
|
||||
return cmd
|
||||
}
|
29
cmd/root.go
29
cmd/root.go
@ -1,17 +1,16 @@
|
||||
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 sugar *zap.SugaredLogger
|
||||
var LOG *zap.SugaredLogger
|
||||
var CFG config.Config
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(load)
|
||||
@ -31,27 +30,27 @@ func init() {
|
||||
func load() {
|
||||
var logger *zap.Logger
|
||||
|
||||
cfg, err := config.Load()
|
||||
CFG, err := config.Load()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if cfg.Debug == "true" {
|
||||
if CFG.Debug == "true" {
|
||||
logger, _ = zap.NewDevelopment()
|
||||
} else {
|
||||
logger, _ = zap.NewProduction()
|
||||
}
|
||||
defer logger.Sync()
|
||||
sugar = logger.Sugar()
|
||||
LOG = logger.Sugar()
|
||||
|
||||
c := ctx.New(&cfg, sugar)
|
||||
_ = loadSystems(&c) // TODO: Handle errs
|
||||
|
||||
tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen())
|
||||
err = tui.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// c := ctx.New(&cfg, LOG)
|
||||
// _ = loadSystems(&c) // TODO: Handle errs
|
||||
//
|
||||
// tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen())
|
||||
// err = tui.Start()
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
}
|
||||
|
||||
func loadSystems(c *ctx.Ctx) []error {
|
||||
@ -81,6 +80,6 @@ var rootCmd = &cobra.Command{
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
sugar.Errorln(err)
|
||||
// LOG.Errorln(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user