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