author | Mikael Berthe <mikael@lilotux.net> |
Fri, 28 Apr 2017 15:39:32 +0200 | |
changeset 20 | b0ccc09f07a2 |
parent 16 | 8939959991b3 |
child 22 | 5778b09bc6fe |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
2 |
// |
|
3 |
// Licensed under the MIT license. |
|
4 |
// Please see the LICENSE file is this directory. |
|
5 |
||
6 |
package cmd |
|
7 |
||
8 |
import ( |
|
9 |
"errors" |
|
16 | 10 |
"os" |
0 | 11 |
"strings" |
12 |
||
13 |
"github.com/spf13/cobra" |
|
6 | 14 |
flag "github.com/spf13/pflag" |
0 | 15 |
|
16 |
"github.com/McKael/madon" |
|
17 |
) |
|
18 |
||
19 |
var accountsOpts struct { |
|
20 |
accountID int |
|
16 | 21 |
accountUID string |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
22 |
unset bool // TODO remove eventually? |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
23 |
limit uint // Limit the number of results |
0 | 24 |
onlyMedia, excludeReplies bool // For acccount statuses |
25 |
remoteUID string // For account follow |
|
26 |
acceptFR, rejectFR bool // For account follow_requests |
|
27 |
list bool // For account follow_requests/reports |
|
28 |
accountIDs string // For account relationships |
|
29 |
statusIDs string // For account reports |
|
30 |
comment string // For account reports |
|
31 |
show bool // For account reports |
|
6 | 32 |
displayName, note string // For account update |
33 |
avatar, header string // For account update |
|
0 | 34 |
} |
35 |
||
6 | 36 |
var updateFlags *flag.FlagSet |
37 |
||
0 | 38 |
func init() { |
39 |
RootCmd.AddCommand(accountsCmd) |
|
40 |
||
41 |
// Subcommands |
|
42 |
accountsCmd.AddCommand(accountSubcommands...) |
|
43 |
||
44 |
// Global flags |
|
45 |
accountsCmd.PersistentFlags().IntVarP(&accountsOpts.accountID, "account-id", "a", 0, "Account ID number") |
|
16 | 46 |
accountsCmd.PersistentFlags().StringVarP(&accountsOpts.accountUID, "user-id", "u", "", "Account user ID") |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
47 |
accountsCmd.PersistentFlags().UintVarP(&accountsOpts.limit, "limit", "l", 0, "Limit number of results") |
0 | 48 |
|
49 |
// Subcommand flags |
|
50 |
accountStatusesSubcommand.Flags().BoolVar(&accountsOpts.onlyMedia, "only-media", false, "Only statuses with media attachments") |
|
51 |
accountStatusesSubcommand.Flags().BoolVar(&accountsOpts.excludeReplies, "exclude-replies", false, "Exclude replies to other statuses") |
|
52 |
||
53 |
accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests") |
|
54 |
accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.acceptFR, "accept", false, "Accept the follow request from the account ID") |
|
55 |
accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.rejectFR, "reject", false, "Reject the follow request from the account ID") |
|
56 |
||
57 |
accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account") |
|
58 |
accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account") |
|
59 |
accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account") |
|
60 |
accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)") |
|
61 |
||
62 |
accountRelationshipsSubcommand.Flags().StringVar(&accountsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs") |
|
63 |
||
64 |
accountReportsSubcommand.Flags().StringVar(&accountsOpts.statusIDs, "status-ids", "", "Comma-separated list of status IDs") |
|
65 |
accountReportsSubcommand.Flags().StringVar(&accountsOpts.comment, "comment", "", "Report comment") |
|
66 |
accountReportsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List current user reports") |
|
6 | 67 |
|
68 |
accountUpdateSubcommand.Flags().StringVar(&accountsOpts.displayName, "display-name", "", "User display name") |
|
69 |
accountUpdateSubcommand.Flags().StringVar(&accountsOpts.note, "note", "", "User note (a.k.a. bio)") |
|
70 |
accountUpdateSubcommand.Flags().StringVar(&accountsOpts.avatar, "avatar", "", "User avatar image") |
|
71 |
accountUpdateSubcommand.Flags().StringVar(&accountsOpts.header, "header", "", "User header image") |
|
72 |
||
73 |
// This one will be used to check if the options were explicitely set or not |
|
74 |
updateFlags = accountUpdateSubcommand.Flags() |
|
0 | 75 |
} |
76 |
||
77 |
// accountsCmd represents the accounts command |
|
78 |
// This command does nothing without a subcommand |
|
79 |
var accountsCmd = &cobra.Command{ |
|
80 |
Use: "accounts [--account-id ID] subcommand", |
|
81 |
Aliases: []string{"account"}, |
|
82 |
Short: "Account-related functions", |
|
83 |
//Long: `TBW...`, // TODO |
|
84 |
//PersistentPreRunE: func(cmd *cobra.Command, args []string) error {}, |
|
85 |
} |
|
86 |
||
87 |
// Note: Some account subcommands are not defined in this file. |
|
88 |
var accountSubcommands = []*cobra.Command{ |
|
89 |
&cobra.Command{ |
|
90 |
Use: "show", |
|
91 |
Long: `Displays the details about the requested account. |
|
92 |
If no account ID is specified, the current user account is used.`, |
|
93 |
Aliases: []string{"display"}, |
|
94 |
Short: "Display the account", |
|
95 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
96 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
97 |
}, |
|
98 |
}, |
|
99 |
&cobra.Command{ |
|
100 |
Use: "followers", |
|
101 |
Short: "Display the accounts following the specified account", |
|
102 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
103 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
104 |
}, |
|
105 |
}, |
|
106 |
&cobra.Command{ |
|
107 |
Use: "following", |
|
108 |
Short: "Display the accounts followed by the specified account", |
|
109 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
110 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
111 |
}, |
|
112 |
}, |
|
113 |
&cobra.Command{ |
|
114 |
Use: "favourites", |
|
115 |
Aliases: []string{"favorites", "favourited", "favorited"}, |
|
116 |
Short: "Display the user's favourites", |
|
117 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
118 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
119 |
}, |
|
120 |
}, |
|
121 |
&cobra.Command{ |
|
122 |
Use: "blocks", |
|
123 |
Aliases: []string{"blocked"}, |
|
124 |
Short: "Display the user's blocked accounts", |
|
125 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
126 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
127 |
}, |
|
128 |
}, |
|
129 |
&cobra.Command{ |
|
130 |
Use: "mutes", |
|
131 |
Aliases: []string{"muted"}, |
|
132 |
Short: "Display the user's muted accounts", |
|
133 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
134 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
135 |
}, |
|
136 |
}, |
|
137 |
&cobra.Command{ |
|
138 |
Use: "search TEXT", |
|
139 |
Short: "Search for user accounts", |
|
140 |
Long: `Search for user accounts. |
|
141 |
The server will lookup an account remotely if the search term is in the |
|
142 |
username@domain format and not yet in the database.`, |
|
143 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
144 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
145 |
}, |
|
146 |
}, |
|
147 |
accountStatusesSubcommand, |
|
148 |
accountFollowRequestsSubcommand, |
|
149 |
accountFollowSubcommand, |
|
150 |
accountBlockSubcommand, |
|
151 |
accountMuteSubcommand, |
|
152 |
accountRelationshipsSubcommand, |
|
153 |
accountReportsSubcommand, |
|
6 | 154 |
accountUpdateSubcommand, |
0 | 155 |
} |
156 |
||
157 |
var accountStatusesSubcommand = &cobra.Command{ |
|
158 |
Use: "statuses", |
|
159 |
Aliases: []string{"st"}, |
|
160 |
Short: "Display the account statuses", |
|
161 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
162 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
163 |
}, |
|
164 |
} |
|
165 |
||
166 |
var accountFollowRequestsSubcommand = &cobra.Command{ |
|
167 |
Use: "follow-requests", |
|
168 |
Aliases: []string{"follow-request", "fr"}, |
|
169 |
Example: ` madonctl accounts follow-requests --list |
|
170 |
madonctl accounts follow-requests --account-id X --accept |
|
171 |
madonctl accounts follow-requests --account-id Y --reject`, |
|
172 |
Short: "List, accept or deny a follow request", |
|
173 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
12
e94c9ed9b1c8
Use cmd.Name() in cobra commands
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
174 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 175 |
}, |
176 |
} |
|
177 |
var accountFollowSubcommand = &cobra.Command{ |
|
178 |
Use: "follow", |
|
179 |
Short: "Follow or unfollow the account", |
|
180 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
12
e94c9ed9b1c8
Use cmd.Name() in cobra commands
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
181 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 182 |
}, |
183 |
} |
|
184 |
||
185 |
var accountBlockSubcommand = &cobra.Command{ |
|
186 |
Use: "block", |
|
187 |
Short: "Block or unblock the account", |
|
188 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
12
e94c9ed9b1c8
Use cmd.Name() in cobra commands
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
189 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 190 |
}, |
191 |
} |
|
192 |
||
193 |
var accountMuteSubcommand = &cobra.Command{ |
|
194 |
Use: "mute", |
|
195 |
Short: "Mute or unmute the account", |
|
196 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
12
e94c9ed9b1c8
Use cmd.Name() in cobra commands
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
197 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 198 |
}, |
199 |
} |
|
200 |
||
201 |
var accountRelationshipsSubcommand = &cobra.Command{ |
|
202 |
Use: "relationships --account-ids ACC1,ACC2...", |
|
203 |
Short: "List relationships with the accounts", |
|
204 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
12
e94c9ed9b1c8
Use cmd.Name() in cobra commands
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
205 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 206 |
}, |
207 |
} |
|
208 |
||
209 |
var accountReportsSubcommand = &cobra.Command{ |
|
210 |
Use: "reports", |
|
211 |
Short: "List reports or report a user account", |
|
212 |
Example: ` madonctl accounts reports --list |
|
213 |
madonctl accounts reports --account-id ACCOUNT --status-ids ID... --comment TEXT`, |
|
214 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
12
e94c9ed9b1c8
Use cmd.Name() in cobra commands
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
215 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 216 |
}, |
217 |
} |
|
218 |
||
6 | 219 |
var accountUpdateSubcommand = &cobra.Command{ |
220 |
Use: "update", |
|
221 |
Short: "Update connected user account", |
|
222 |
Long: `Update connected user account |
|
223 |
||
224 |
All flags are optional (set to an empty string if you want to delete a field). |
|
225 |
The flags --avatar and --header can be paths to image files or base64-encoded |
|
226 |
images (see Mastodon API specifications for the details). |
|
227 |
||
228 |
Please note the avatar and header images cannot be removed, they can only be |
|
229 |
replaced.`, |
|
230 |
Example: ` madonctl accounts update --display-name "Mr President" |
|
231 |
madonctl accounts update --note "I like madonctl" |
|
232 |
madonctl accounts update --avatar happyface.png`, |
|
233 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
234 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
235 |
}, |
|
236 |
} |
|
237 |
||
0 | 238 |
// accountSubcommandsRunE is a generic function for status subcommands |
239 |
func accountSubcommandsRunE(subcmd string, args []string) error { |
|
240 |
opt := accountsOpts |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
241 |
var limOpts *madon.LimitParams |
0 | 242 |
|
16 | 243 |
if opt.accountUID != "" { |
244 |
if opt.accountID > 0 { |
|
245 |
return errors.New("cannot use both account ID and UID") |
|
246 |
} |
|
247 |
// Remove leading '@' |
|
248 |
opt.accountUID = strings.TrimLeft(opt.accountUID, "@") |
|
249 |
// Sign in early to look the user id up |
|
250 |
if err := madonInit(true); err != nil { |
|
251 |
return err |
|
252 |
} |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
253 |
accList, err := gClient.SearchAccounts(opt.accountUID, &madon.LimitParams{Limit: 2}) |
16 | 254 |
if err != nil || len(accList) < 1 { |
255 |
errPrint("Cannot find user '%s': %v", opt.accountUID, err) |
|
256 |
os.Exit(1) |
|
257 |
} |
|
258 |
for _, u := range accList { |
|
259 |
if u.Acct == opt.accountUID { |
|
260 |
opt.accountID = u.ID |
|
261 |
break |
|
262 |
} |
|
263 |
} |
|
264 |
if opt.accountID < 1 { |
|
265 |
errPrint("Cannot find user '%s'", opt.accountUID) |
|
266 |
os.Exit(1) |
|
267 |
} |
|
268 |
if verbose { |
|
269 |
errPrint("User '%s' is account ID %d", opt.accountUID, opt.accountID) |
|
270 |
} |
|
271 |
} |
|
272 |
||
0 | 273 |
switch subcmd { |
6 | 274 |
case "show", "search", "update": |
0 | 275 |
// These subcommands do not require an account ID |
276 |
case "favourites", "blocks", "mutes": |
|
277 |
// Those subcommands can not use an account ID |
|
278 |
if opt.accountID > 0 { |
|
279 |
return errors.New("useless account ID") |
|
280 |
} |
|
281 |
case "follow": |
|
282 |
if opt.accountID < 1 && opt.remoteUID == "" { |
|
283 |
return errors.New("missing account ID or URI") |
|
284 |
} |
|
285 |
if opt.accountID > 0 && opt.remoteUID != "" { |
|
286 |
return errors.New("cannot use both account ID and URI") |
|
287 |
} |
|
288 |
if opt.unset && opt.accountID < 1 { |
|
289 |
return errors.New("unfollowing requires an account ID") |
|
290 |
} |
|
291 |
case "follow-requests": |
|
292 |
if opt.list { |
|
293 |
if opt.acceptFR || opt.rejectFR { |
|
294 |
return errors.New("incompatible options") |
|
295 |
} |
|
296 |
} else { |
|
297 |
if !opt.acceptFR && !opt.rejectFR { // No flag |
|
298 |
return errors.New("missing parameter (--list, --accept or --reject)") |
|
299 |
} |
|
300 |
// This is a FR reply |
|
301 |
if opt.acceptFR && opt.rejectFR { |
|
302 |
return errors.New("incompatible options") |
|
303 |
} |
|
304 |
if opt.accountID < 1 { |
|
305 |
return errors.New("missing account ID") |
|
306 |
} |
|
307 |
} |
|
308 |
case "relationships": |
|
309 |
if opt.accountID < 1 && len(opt.accountIDs) == 0 { |
|
310 |
return errors.New("missing account IDs") |
|
311 |
} |
|
312 |
if opt.accountID > 0 && len(opt.accountIDs) > 0 { |
|
313 |
return errors.New("incompatible options") |
|
314 |
} |
|
315 |
case "reports": |
|
316 |
if opt.list { |
|
317 |
break // No argument needed |
|
318 |
} |
|
319 |
if opt.accountID < 1 || len(opt.statusIDs) == 0 || opt.comment == "" { |
|
320 |
return errors.New("missing parameter") |
|
321 |
} |
|
322 |
default: |
|
323 |
// The other subcommands here require an account ID |
|
324 |
if opt.accountID < 1 { |
|
325 |
return errors.New("missing account ID") |
|
326 |
} |
|
327 |
} |
|
328 |
||
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
329 |
if opt.limit > 0 { |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
330 |
if limOpts == nil { |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
331 |
limOpts = new(madon.LimitParams) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
332 |
} |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
333 |
limOpts.Limit = int(opt.limit) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
334 |
} |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
335 |
|
0 | 336 |
// All account subcommands need to have signed in |
337 |
if err := madonInit(true); err != nil { |
|
338 |
return err |
|
339 |
} |
|
340 |
||
341 |
var obj interface{} |
|
342 |
var err error |
|
343 |
||
344 |
switch subcmd { |
|
345 |
case "show": |
|
346 |
var account *madon.Account |
|
347 |
if opt.accountID > 0 { |
|
348 |
account, err = gClient.GetAccount(opt.accountID) |
|
349 |
} else { |
|
350 |
account, err = gClient.GetCurrentAccount() |
|
351 |
} |
|
352 |
obj = account |
|
353 |
case "search": |
|
354 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
355 |
accountList, err = gClient.SearchAccounts(strings.Join(args, " "), limOpts) |
0 | 356 |
obj = accountList |
357 |
case "followers": |
|
358 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
359 |
accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
360 |
if opt.limit > 0 && len(accountList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
361 |
accountList = accountList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
362 |
} |
0 | 363 |
obj = accountList |
364 |
case "following": |
|
365 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
366 |
accountList, err = gClient.GetAccountFollowing(opt.accountID, limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
367 |
if opt.limit > 0 && len(accountList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
368 |
accountList = accountList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
369 |
} |
0 | 370 |
obj = accountList |
371 |
case "statuses": |
|
372 |
var statusList []madon.Status |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
373 |
statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies, limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
374 |
if opt.limit > 0 && len(statusList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
375 |
statusList = statusList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
376 |
} |
0 | 377 |
obj = statusList |
378 |
case "follow": |
|
379 |
if opt.unset { |
|
380 |
err = gClient.UnfollowAccount(opt.accountID) |
|
381 |
} else { |
|
382 |
if opt.accountID > 0 { |
|
383 |
err = gClient.FollowAccount(opt.accountID) |
|
384 |
} else { |
|
385 |
var account *madon.Account |
|
386 |
account, err = gClient.FollowRemoteAccount(opt.remoteUID) |
|
387 |
obj = account |
|
388 |
} |
|
389 |
} |
|
390 |
case "follow-requests": |
|
391 |
if opt.list { |
|
392 |
var followRequests []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
393 |
followRequests, err = gClient.GetAccountFollowRequests(limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
394 |
if opt.limit > 0 && len(followRequests) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
395 |
followRequests = followRequests[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
396 |
} |
0 | 397 |
obj = followRequests |
398 |
} else { |
|
399 |
err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR) |
|
400 |
} |
|
401 |
case "block": |
|
402 |
if opt.unset { |
|
403 |
err = gClient.UnblockAccount(opt.accountID) |
|
404 |
} else { |
|
405 |
err = gClient.BlockAccount(opt.accountID) |
|
406 |
} |
|
407 |
case "mute": |
|
408 |
if opt.unset { |
|
409 |
err = gClient.UnmuteAccount(opt.accountID) |
|
410 |
} else { |
|
411 |
err = gClient.MuteAccount(opt.accountID) |
|
412 |
} |
|
413 |
case "favourites": |
|
414 |
var statusList []madon.Status |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
415 |
statusList, err = gClient.GetFavourites(limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
416 |
if opt.limit > 0 && len(statusList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
417 |
statusList = statusList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
418 |
} |
0 | 419 |
obj = statusList |
420 |
case "blocks": |
|
421 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
422 |
accountList, err = gClient.GetBlockedAccounts(limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
423 |
if opt.limit > 0 && len(accountList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
424 |
accountList = accountList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
425 |
} |
0 | 426 |
obj = accountList |
427 |
case "mutes": |
|
428 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
429 |
accountList, err = gClient.GetMutedAccounts(limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
430 |
if opt.limit > 0 && len(accountList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
431 |
accountList = accountList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
432 |
} |
0 | 433 |
obj = accountList |
434 |
case "relationships": |
|
435 |
var ids []int |
|
436 |
ids, err = splitIDs(opt.accountIDs) |
|
437 |
if err != nil { |
|
438 |
return errors.New("cannot parse account IDs") |
|
439 |
} |
|
440 |
if opt.accountID > 0 { // Allow --account-id |
|
441 |
ids = []int{opt.accountID} |
|
442 |
} |
|
443 |
if len(ids) < 1 { |
|
444 |
return errors.New("missing account IDs") |
|
445 |
} |
|
446 |
var relationships []madon.Relationship |
|
447 |
relationships, err = gClient.GetAccountRelationships(ids) |
|
448 |
obj = relationships |
|
449 |
case "reports": |
|
450 |
if opt.list { |
|
451 |
var reports []madon.Report |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
452 |
reports, err = gClient.GetReports(limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
453 |
if opt.limit > 0 && len(reports) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
454 |
reports = reports[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
455 |
} |
0 | 456 |
obj = reports |
457 |
break |
|
458 |
} |
|
459 |
// Send a report |
|
460 |
var ids []int |
|
461 |
ids, err = splitIDs(opt.statusIDs) |
|
462 |
if err != nil { |
|
463 |
return errors.New("cannot parse status IDs") |
|
464 |
} |
|
465 |
if len(ids) < 1 { |
|
466 |
return errors.New("missing status IDs") |
|
467 |
} |
|
468 |
var report *madon.Report |
|
469 |
report, err = gClient.ReportUser(opt.accountID, ids, opt.comment) |
|
470 |
obj = report |
|
6 | 471 |
case "update": |
472 |
var dn, note, avatar, header *string |
|
473 |
change := false |
|
474 |
if updateFlags.Lookup("display-name").Changed { |
|
475 |
dn = &opt.displayName |
|
476 |
change = true |
|
477 |
} |
|
478 |
if updateFlags.Lookup("note").Changed { |
|
479 |
note = &opt.note |
|
480 |
change = true |
|
481 |
} |
|
482 |
if updateFlags.Lookup("avatar").Changed { |
|
483 |
avatar = &opt.avatar |
|
484 |
change = true |
|
485 |
} |
|
486 |
if updateFlags.Lookup("header").Changed { |
|
487 |
header = &opt.header |
|
488 |
change = true |
|
489 |
} |
|
490 |
||
491 |
if !change { // We want at least one update |
|
492 |
return errors.New("missing parameters") |
|
493 |
} |
|
494 |
||
495 |
var account *madon.Account |
|
496 |
account, err = gClient.UpdateAccount(dn, note, avatar, header) |
|
497 |
obj = account |
|
0 | 498 |
default: |
499 |
return errors.New("accountSubcommand: internal error") |
|
500 |
} |
|
501 |
||
502 |
if err != nil { |
|
503 |
errPrint("Error: %s", err.Error()) |
|
504 |
return nil |
|
505 |
} |
|
506 |
if obj == nil { |
|
507 |
return nil |
|
508 |
} |
|
509 |
||
510 |
p, err := getPrinter() |
|
511 |
if err != nil { |
|
512 |
return err |
|
513 |
} |
|
514 |
return p.PrintObj(obj, nil, "") |
|
515 |
} |