all repos — underbbs @ a7e5c99cecb4fb19335c1bdd27ab827e59850476

decentralized social media client

cli/cli.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
}