cli.go (view raw)
1package main
2
3import (
4 "fmt"
5 "os"
6 "strconv"
7)
8
9type cmd struct {
10 help string
11 callback func(args []string)
12}
13
14var commands = map[string]cmd{
15 "initdb": {
16 help: "initialize honk",
17 callback: func(args []string) {
18 initdb()
19 },
20 },
21 "upgrade": {
22 help: "upgrade honk",
23 callback: func(args []string) {
24 upgradedb()
25 },
26 },
27 "version": {
28 help: "print version",
29 callback: func(args []string) {
30 fmt.Println(softwareVersion)
31 os.Exit(0)
32 },
33 },
34 "admin": {
35 help: "admin interface",
36 callback: func(args []string) {
37 adminscreen()
38 },
39 },
40 "import": {
41 help: "import data into honk",
42 callback: func(args []string) {
43 if len(args) != 4 {
44 errx("import username honk|mastodon|twitter srcdir")
45 }
46 importMain(args[1], args[2], args[3])
47 },
48 },
49 "export": {
50 help: "export data from honk",
51 callback: func(args []string) {
52 if len(args) != 3 {
53 errx("export username destdir")
54 }
55 export(args[1], args[2])
56 },
57 },
58 "devel": {
59 help: "turn devel on/off",
60 callback: func(args []string) {
61 if len(args) != 2 {
62 errx("need an argument: devel (on|off)")
63 }
64 switch args[1] {
65 case "on":
66 setconfig("devel", 1)
67 case "off":
68 setconfig("devel", 0)
69 default:
70 errx("argument must be on or off")
71 }
72 },
73 },
74 "setconfig": {
75 help: "set honk config",
76 callback: func(args []string) {
77 if len(args) != 3 {
78 errx("need an argument: setconfig key val")
79 }
80 var val interface{}
81 var err error
82 if val, err = strconv.Atoi(args[2]); err != nil {
83 val = args[2]
84 }
85 setconfig(args[1], val)
86 },
87 },
88 "adduser": {
89 help: "add a user to honk",
90 callback: func(args []string) {
91 adduser()
92 },
93 },
94 "deluser": {
95 help: "delete a user from honk",
96 callback: func(args []string) {
97 if len(args) < 2 {
98 errx("usage: honk deluser username")
99 }
100 deluser(args[1])
101 },
102 },
103 "chpass": {
104 help: "change password of an account",
105 callback: func(args []string) {
106 if len(args) < 2 {
107 errx("usage: honk chpass username")
108 }
109 chpass(args[1])
110 },
111 },
112 "follow": {
113 help: "follow an account",
114 callback: func(args []string) {
115 if len(args) < 3 {
116 errx("usage: honk follow username url")
117 }
118 user, err := butwhatabout(args[1])
119 if err != nil {
120 errx("user %s not found", args[1])
121 }
122 var meta HonkerMeta
123 mj, _ := jsonify(&meta)
124 honkerid, flavor, err := savehonker(user, args[2], "", "presub", "", mj)
125 if err != nil {
126 errx("had some trouble with that: %s", err)
127 }
128 if flavor == "presub" {
129 followyou(user, honkerid, true)
130 }
131 },
132 },
133 "unfollow": {
134 help: "unfollow an account",
135 callback: func(args []string) {
136 if len(args) < 3 {
137 errx("usage: honk unfollow username url")
138 }
139 user, err := butwhatabout(args[1])
140 if err != nil {
141 errx("user not found")
142 }
143
144 honkerid, err := gethonker(user.ID, args[2])
145 if err != nil {
146 errx("sorry couldn't find them")
147 }
148 unfollowyou(user, honkerid, true)
149 },
150 },
151 "sendmsg": {
152 help: "send a message",
153 callback: func(args []string) {
154 if len(args) < 4 {
155 errx("usage: honk send username filename rcpt")
156 }
157 user, err := butwhatabout(args[1])
158 if err != nil {
159 errx("user %s not found", args[1])
160 }
161 data, err := os.ReadFile(args[2])
162 if err != nil {
163 errx("can't read file: %s", err)
164 }
165 deliverate(user.ID, args[3], data)
166 },
167 },
168 "cleanup": {
169 help: "clean up? (enter usefull )",
170 callback: func(args []string) {
171 arg := "30"
172 if len(args) > 1 {
173 arg = args[1]
174 }
175 cleanupdb(arg)
176 },
177 },
178 "unplug": {
179 help: "not sure",
180 callback: func(args []string) {
181 if len(args) < 2 {
182 errx("usage: honk unplug servername")
183 }
184 name := args[1]
185 unplugserver(name)
186 },
187 },
188 "backup": {
189 help: "backup honk",
190 callback: func(args []string) {
191 if len(args) < 2 {
192 errx("usage: honk backup dirname")
193 }
194 name := args[1]
195 svalbard(name)
196 },
197 },
198 "ping": {
199 help: "ping from user to user/url",
200 callback: func(args []string) {
201 if len(args) < 3 {
202 errx("usage: honk ping (from username) (to username or url)")
203 }
204 name := args[1]
205 targ := args[2]
206 user, err := butwhatabout(name)
207 if err != nil {
208 errx("unknown user %s", name)
209 }
210 ping(user, targ)
211 },
212 },
213 "run": {
214 help: "run honk",
215 callback: func(args []string) {
216 serve()
217 },
218 },
219 "backend": {
220 help: "run backend",
221 callback: func(args []string) {
222 backendServer()
223 },
224 },
225 "test": {
226 help: "run test",
227 callback: func(args []string) {
228 ElaborateUnitTests()
229 },
230 },
231}