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