all repos — underbbs @ a7e5c99cecb4fb19335c1bdd27ab827e59850476

decentralized social media client

add skeleton for CLI processor
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZvymmQAKCRBohAcXSWbK
85ubAQCGclzoD61meTBY39voYRFaAmIUEIkSV1nHKWWB7FY3qgEA4PdkcQmIyZJ6
9Uzc+jYWly+JPTFEqAHGbm/UETZOFQY=
=cNsJ
-----END PGP SIGNATURE-----
commit

a7e5c99cecb4fb19335c1bdd27ab827e59850476

parent

c6cfdf9e9f189592736718719d97e6ff343b5efe

2 files changed, 59 insertions(+), 1 deletions(-)

jump to
A cli/cli.go

@@ -0,0 +1,57 @@

+package cli + +import ( + "encoding/json" + "io/ioutil" + "log" + + "forge.lightcrystal.systems/lightcrystal/underbbs/adapter" + "forge.lightcrystal.systems/lightcrystal/underbbs/models" +) + +func Process(args ...string) error { + // allocate storage for the settings array + var settings []models.Settings + var s models.Settings + + // get adapter from first arg + adapterName := args[0] + args = args[1:] + + // get config from config fle based on adapter + content, err := ioutil.ReadFile("./config.json") + if err != nil { + return err + } + + err = json.Unmarshal(content, settings) + if err != nil { + return err + } + for _, x := range settings { + if x.Nickname == adapterName { + s = x + break + } + } + // instantiate adapter with config + var a adapter.Adapter + switch s.Protocol { + case "nostr": + a = &adapter.NostrAdapter{} + case "mastodon": + a = &adapter.MastoAdapter{} + case "misskey": + a = &adapter.MisskeyAdapter{} + default: + break + } + a.Init(s, nil) + // process remaining args and execute + + switch args[0] { + default: + log.Print(args) + } + return nil +}
M underbbs.gounderbbs.go

@@ -11,6 +11,7 @@ "path/filepath"

"strconv" "time" + "forge.lightcrystal.systems/lightcrystal/underbbs/cli" "forge.lightcrystal.systems/lightcrystal/underbbs/server" )

@@ -35,7 +36,7 @@ }

} func run_cli(args ...string) error { - log.Print("test!!") + cli.Process(args...) return nil }