forked from mattn/bsky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
233 lines (225 loc) · 6.07 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
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
const name = "bsky"
const version = "0.0.11"
var revision = "HEAD"
type config struct {
Host string `json:"host"`
Handle string `json:"handle"`
Password string `json:"password"`
dir string
verbose bool
}
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",
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: "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: "handle", Aliases: []string{"H"}, Value: "", Usage: "user handle"},
&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.BoolFlag{Name: "stdin"},
&cli.StringSliceFlag{Name: "image", Aliases: []string{"i"}},
},
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: "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: "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,
},
},
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")
return nil
},
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}