forked from mattn/bsky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
328 lines (320 loc) · 8.89 KB
/
main.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
const name = "bsky"
const version = "0.0.47"
var revision = "HEAD"
type config struct {
Host string `json:"host"`
Handle string `json:"handle"`
Password string `json:"password"`
dir string
verbose bool
prefix string
}
func main() {
app := &cli.App{
Name: name,
Usage: name,
Version: version,
Description: "A cli application for bluesky",
Flags: []cli.Flag{
&cli.StringFlag{Name: "a", Usage: "profile name"},
&cli.BoolFlag{Name: "V", Usage: "verbose"},
},
Commands: []*cli.Command{
{
Name: "show-profile",
Description: "Show profile",
Usage: "Show profile",
UsageText: "bsky show-profile",
Flags: []cli.Flag{
&cli.StringFlag{Name: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
Action: doShowProfile,
},
{
Name: "update-profile",
Description: "Update profile",
Usage: "Update profile",
UsageText: "bsky update-profile [OPTIONS]... [{display name} [description]]",
Flags: []cli.Flag{
&cli.StringFlag{Name: "avatar", Value: "", Usage: "avatar image", TakesFile: true},
&cli.StringFlag{Name: "banner", Value: "", Usage: "banner image", TakesFile: true},
},
Action: doUpdateProfile,
},
{
Name: "show-session",
Description: "Show session",
Usage: "Show session",
UsageText: "bsky show-session",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
Action: doShowSession,
},
{
Name: "timeline",
Description: "Show timeline",
Usage: "Show timeline",
UsageText: "bsky timeline",
Aliases: []string{"tl"},
Flags: []cli.Flag{
&cli.StringFlag{Name: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&cli.IntFlag{Name: "n", Value: 30, Usage: "number of items"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
Action: doTimeline,
},
{
Name: "stream",
Description: "Show timeline as stream",
Usage: "Show timeline as stream",
UsageText: "bsky stream",
Flags: []cli.Flag{
&cli.StringFlag{Name: "cursor", Value: "", Usage: "cursor"},
&cli.StringFlag{Name: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&cli.StringFlag{Name: "pattern", Usage: "pattern"},
&cli.StringFlag{Name: "reply", Usage: "reply"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
Action: doStream,
},
{
Name: "thread",
Description: "Show thread",
Usage: "Show thread",
UsageText: "bsky thread [uri]",
Flags: []cli.Flag{
&cli.IntFlag{Name: "n", Value: 30, Usage: "number of items"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
Action: doThread,
},
{
Name: "post",
Description: "Post new text",
Usage: "Post new text",
UsageText: "bsky post [text]",
Flags: []cli.Flag{
&cli.StringFlag{Name: "r"},
&cli.StringFlag{Name: "q"},
&cli.StringFlag{Name: "l"},
&cli.BoolFlag{Name: "stdin"},
&cli.StringSliceFlag{Name: "image", Aliases: []string{"i"}},
&cli.StringSliceFlag{Name: "image-alt", Aliases: []string{"ia"}},
},
HelpName: "post",
ArgsUsage: "[text]",
Action: doPost,
},
{
Name: "vote",
Description: "Vote the post",
Usage: "Vote the post",
UsageText: "bsky vote [uri]",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "down"},
},
HelpName: "vote",
Action: doVote,
},
{
Name: "votes",
Description: "Show votes of the post",
Usage: "Show votes of the post",
UsageText: "bsky votes [uri]",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "votes",
Action: doVotes,
ArgsUsage: "[uri]",
},
{
Name: "repost",
Description: "Repost the post",
Usage: "Repost the post",
UsageText: "bsky repost [uri]",
HelpName: "repost",
Action: doRepost,
},
{
Name: "reposts",
Description: "Show reposts of the post",
Usage: "Show reposts of the post",
UsageText: "bsky reposts [uri]",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "reposts",
Action: doReposts,
},
{
Name: "follow",
Description: "Follow the handle",
Usage: "Follow the handle",
UsageText: "bsky follow [handle]",
HelpName: "follow",
Action: doFollow,
},
{
Name: "unfollow",
Description: "Unfollow the handle",
Usage: "Unfollow the handle",
UsageText: "bsky unfollow [handle]",
HelpName: "unfollow",
Action: doUnfollow,
},
{
Name: "follows",
Description: "Show follows",
Usage: "Show follows",
UsageText: "bsky follows",
Flags: []cli.Flag{
&cli.StringFlag{Name: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "follows",
Action: doFollows,
},
{
Name: "followers",
Description: "Show followers",
Usage: "Show followers",
UsageText: "bsky followres",
Flags: []cli.Flag{
&cli.StringFlag{Name: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "followers",
Action: doFollowers,
},
{
Name: "block",
Description: "Block the handle",
Usage: "Block the handle",
UsageText: "bsky block [handle]",
HelpName: "block",
Action: doBlock,
},
{
Name: "unblock",
Description: "Unblock the handle",
Usage: "Unblock the handle",
UsageText: "bsky unblock [handle]",
HelpName: "unblock",
Action: doUnblock,
},
{
Name: "blocks",
Description: "Show blocks",
Usage: "Show blocks",
UsageText: "bsky blocks",
Flags: []cli.Flag{
&cli.StringFlag{Name: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "blocks",
Action: doBlocks,
},
{
Name: "delete",
Description: "Delete the note",
Usage: "Delete the note",
UsageText: "bsky delete [cid]",
HelpName: "delete",
Action: doDelete,
},
{
Name: "login",
Description: "Login the social",
Usage: "Login the social",
UsageText: "bsky login [handle] [password]",
Flags: []cli.Flag{
&cli.StringFlag{Name: "host", Value: "https://bsky.social"},
},
HelpName: "login",
Action: doLogin,
},
{
Name: "notification",
Description: "Show notifications",
Usage: "Show notifications",
UsageText: "bsky notification",
Aliases: []string{"notif"},
Flags: []cli.Flag{
&cli.BoolFlag{Name: "a", Usage: "show all"},
},
HelpName: "notification",
Action: doNotification,
},
{
Name: "invite-codes",
Description: "Show invite codes",
Usage: "Show invite codes",
UsageText: "bsky invite-codes",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "used", Usage: "show used codes too"},
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "invite-codes",
Action: doInviteCodes,
},
{
Name: "list-app-passwords",
Description: "Show App-passwords",
Usage: "Show App-passwords",
UsageText: "bsky list-app-passwords",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "json", Usage: "output JSON"},
},
HelpName: "list-app-passwords",
Action: doListAppPasswords,
},
{
Name: "add-app-password",
Description: "Add App-password",
Usage: "Add App-password",
UsageText: "bsky add-app-password",
HelpName: "add-app-password",
Action: doAddAppPassword,
},
{
Name: "revoke-app-password",
Description: "Revoke App-password",
Usage: "Revoke App-password",
UsageText: "bsky revoke-app-password",
HelpName: "revoke-app-password",
Action: doRevokeAppPassword,
},
},
Metadata: map[string]any{},
Before: func(cCtx *cli.Context) error {
profile := cCtx.String("a")
cfg, fp, err := loadConfig(profile)
cCtx.App.Metadata["path"] = fp
if cCtx.Args().Get(0) == "login" {
return nil
}
if err != nil {
return fmt.Errorf("cannot load config file: %w", err)
}
cCtx.App.Metadata["config"] = cfg
cfg.verbose = cCtx.Bool("V")
if profile != "" {
cfg.prefix = profile + "-"
}
return nil
},
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}