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