author | Mikael Berthe <mikael@lilotux.net> |
Sat, 04 Feb 2023 13:35:58 +0100 | |
changeset 271 | c8b8b7cc8896 |
parent 268 | 4dd196a4ee7c |
permissions | -rw-r--r-- |
265
05c40b36d3b2
Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents:
239
diff
changeset
|
1 |
// Copyright © 2017-2023 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" |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
10 |
"strconv" |
0 | 11 |
"strings" |
12 |
||
45
b58a7ea1aeb2
Use github.com/pkg/errors
Mikael Berthe <mikael@lilotux.net>
parents:
44
diff
changeset
|
13 |
"github.com/pkg/errors" |
0 | 14 |
"github.com/spf13/cobra" |
6 | 15 |
flag "github.com/spf13/pflag" |
0 | 16 |
|
265
05c40b36d3b2
Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents:
239
diff
changeset
|
17 |
"github.com/McKael/madon/v3" |
0 | 18 |
) |
19 |
||
205
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
20 |
var accountUpdateFlags, accountMuteFlags, accountFollowFlags *flag.FlagSet |
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
21 |
|
0 | 22 |
var accountsOpts struct { |
267 | 23 |
accountID madon.ActivityID |
180
9bcc6dc003fd
Add '--pinned' flag to madonctl account statuses
Mikael Berthe <mikael@lilotux.net>
parents:
178
diff
changeset
|
24 |
accountUID string |
267 | 25 |
limit, keep uint // Limit the results |
26 |
sinceID, maxID madon.ActivityID // Query boundaries |
|
27 |
all bool // Try to fetch all results |
|
28 |
onlyMedia, onlyPinned bool // For acccount statuses |
|
29 |
excludeReplies bool // For acccount statuses |
|
30 |
remoteUID string // For account follow |
|
31 |
reblogs bool // For account follow |
|
32 |
acceptFR, rejectFR bool // For account follow_requests |
|
33 |
list bool // For account follow_requests/reports |
|
34 |
accountIDs string // For account relationships |
|
35 |
statusIDs string // For account reports |
|
36 |
comment string // For account reports |
|
37 |
displayName, note string // For account update |
|
38 |
profileFields []string // For account update |
|
39 |
avatar, header string // For account update |
|
40 |
defaultLanguage string // For account update |
|
41 |
defaultPrivacy string // For account update |
|
42 |
defaultSensitive bool // For account update |
|
43 |
locked, bot bool // For account update |
|
44 |
muteNotifications bool // For account mute |
|
45 |
following bool // For account search |
|
0 | 46 |
} |
47 |
||
48 |
func init() { |
|
49 |
RootCmd.AddCommand(accountsCmd) |
|
50 |
||
51 |
// Subcommands |
|
52 |
accountsCmd.AddCommand(accountSubcommands...) |
|
53 |
||
54 |
// Global flags |
|
267 | 55 |
accountsCmd.PersistentFlags().StringVarP(&accountsOpts.accountID, "account-id", "a", "", "Account ID number") |
16 | 56 |
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
|
57 |
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
|
58 |
accountsCmd.PersistentFlags().UintVarP(&accountsOpts.keep, "keep", "k", 0, "Limit number of results") |
267 | 59 |
accountsCmd.PersistentFlags().StringVar(&accountsOpts.sinceID, "since-id", "", "Request IDs greater than a value") |
60 |
accountsCmd.PersistentFlags().StringVar(&accountsOpts.maxID, "max-id", "", "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
|
61 |
accountsCmd.PersistentFlags().BoolVar(&accountsOpts.all, "all", false, "Fetch all results") |
0 | 62 |
|
63 |
// Subcommand flags |
|
180
9bcc6dc003fd
Add '--pinned' flag to madonctl account statuses
Mikael Berthe <mikael@lilotux.net>
parents:
178
diff
changeset
|
64 |
accountStatusesSubcommand.Flags().BoolVar(&accountsOpts.onlyPinned, "pinned", false, "Only statuses that have been pinned") |
0 | 65 |
accountStatusesSubcommand.Flags().BoolVar(&accountsOpts.onlyMedia, "only-media", false, "Only statuses with media attachments") |
66 |
accountStatusesSubcommand.Flags().BoolVar(&accountsOpts.excludeReplies, "exclude-replies", false, "Exclude replies to other statuses") |
|
67 |
||
68 |
accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests") |
|
69 |
accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.acceptFR, "accept", false, "Accept the follow request from the account ID") |
|
70 |
accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.rejectFR, "reject", false, "Reject the follow request from the account ID") |
|
71 |
||
182
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
72 |
accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.muteNotifications, "notifications", "", true, "Mute the notifications") |
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") |
|
224
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
88 |
accountUpdateSubcommand.Flags().StringArrayVar(&accountsOpts.profileFields, "profile-field", nil, "Profile metadata field (NAME=VALUE)") |
223
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
89 |
accountUpdateSubcommand.Flags().StringVar(&accountsOpts.defaultLanguage, "default-language", "", "Default toots language (iso 639 code)") |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
90 |
accountUpdateSubcommand.Flags().StringVar(&accountsOpts.defaultPrivacy, "default-privacy", "", "Default toot privacy (public, unlisted, private)") |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
91 |
accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.defaultSensitive, "default-sensitive", false, "Mark medias as sensitive by default") |
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
92 |
accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.locked, "locked", false, "Following account requires approval") |
222
e93d9c738273
Add '--bot' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
220
diff
changeset
|
93 |
accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.bot, "bot", false, "Set as service (automated) account") |
6 | 94 |
|
205
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
95 |
// 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
|
96 |
// explicitly set or not |
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
97 |
accountUpdateFlags = accountUpdateSubcommand.Flags() |
182
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
98 |
accountMuteFlags = accountMuteSubcommand.Flags() |
205
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
99 |
accountFollowFlags = accountFollowSubcommand.Flags() |
0 | 100 |
} |
101 |
||
102 |
// accountsCmd represents the accounts command |
|
103 |
// This command does nothing without a subcommand |
|
104 |
var accountsCmd = &cobra.Command{ |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
105 |
Use: "account [--account-id ID] subcommand", |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
106 |
Aliases: []string{"accounts"}, |
0 | 107 |
Short: "Account-related functions", |
108 |
//Long: `TBW...`, // TODO |
|
109 |
} |
|
110 |
||
111 |
// Note: Some account subcommands are not defined in this file. |
|
112 |
var accountSubcommands = []*cobra.Command{ |
|
113 |
&cobra.Command{ |
|
114 |
Use: "show", |
|
115 |
Long: `Displays the details about the requested account. |
|
116 |
If no account ID is specified, the current user account is used.`, |
|
117 |
Aliases: []string{"display"}, |
|
118 |
Short: "Display the account", |
|
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
119 |
Example: ` madonctl account show # Display your own account |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
120 |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
121 |
madonctl account show --account-id 1234 |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
122 |
madonctl account show --user-id Gargron@mastodon.social |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
123 |
madonctl account show --user-id https://mastodon.social/@Gargron |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
124 |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
125 |
madonctl account show 1234 |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
126 |
madonctl account show Gargron@mastodon.social |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
127 |
madonctl account show https://mastodon.social/@Gargron |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
128 |
`, |
0 | 129 |
RunE: func(cmd *cobra.Command, args []string) error { |
130 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
131 |
}, |
|
132 |
}, |
|
133 |
&cobra.Command{ |
|
134 |
Use: "followers", |
|
135 |
Short: "Display the accounts following the specified account", |
|
136 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
137 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
138 |
}, |
|
139 |
}, |
|
140 |
&cobra.Command{ |
|
141 |
Use: "following", |
|
142 |
Short: "Display the accounts followed by the specified account", |
|
143 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
144 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
145 |
}, |
|
146 |
}, |
|
147 |
&cobra.Command{ |
|
148 |
Use: "favourites", |
|
149 |
Aliases: []string{"favorites", "favourited", "favorited"}, |
|
150 |
Short: "Display the user's favourites", |
|
151 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
152 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
153 |
}, |
|
154 |
}, |
|
155 |
&cobra.Command{ |
|
156 |
Use: "blocks", |
|
157 |
Aliases: []string{"blocked"}, |
|
158 |
Short: "Display the user's blocked accounts", |
|
159 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
160 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
161 |
}, |
|
162 |
}, |
|
163 |
&cobra.Command{ |
|
164 |
Use: "mutes", |
|
165 |
Aliases: []string{"muted"}, |
|
166 |
Short: "Display the user's muted accounts", |
|
167 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
168 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
169 |
}, |
|
170 |
}, |
|
184
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
171 |
accountSearchSubcommand, |
0 | 172 |
accountStatusesSubcommand, |
173 |
accountFollowRequestsSubcommand, |
|
174 |
accountFollowSubcommand, |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
175 |
accountUnfollowSubcommand, |
0 | 176 |
accountBlockSubcommand, |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
177 |
accountUnblockSubcommand, |
0 | 178 |
accountMuteSubcommand, |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
179 |
accountUnmuteSubcommand, |
226
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
180 |
accountPinSubcommand, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
181 |
accountUnpinSubcommand, |
0 | 182 |
accountRelationshipsSubcommand, |
183 |
accountReportsSubcommand, |
|
6 | 184 |
accountUpdateSubcommand, |
226
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
185 |
accountListEndorsementsSubcommand, |
0 | 186 |
} |
187 |
||
184
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
188 |
var accountSearchSubcommand = &cobra.Command{ |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
189 |
Use: "search TEXT", |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
190 |
Short: "Search for user accounts", |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
191 |
Long: `Search for user accounts. |
196
05861d22b71e
Fix help for account search
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
192 |
|
05861d22b71e
Fix help for account search
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
193 |
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
|
194 |
@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
|
195 |
RunE: func(cmd *cobra.Command, args []string) error { |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
196 |
return accountSubcommandsRunE(cmd.Name(), args) |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
197 |
}, |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
198 |
} |
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
199 |
|
0 | 200 |
var accountStatusesSubcommand = &cobra.Command{ |
201 |
Use: "statuses", |
|
202 |
Aliases: []string{"st"}, |
|
203 |
Short: "Display the account statuses", |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
204 |
Example: ` madonctl account statuses |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
205 |
madonctl account statuses 404 # local account numeric ID |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
206 |
madonctl account statuses @McKael # local account |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
207 |
madonctl account statuses Gargron@mastodon.social # remote (known account) |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
208 |
madonctl account statuses https://mastodon.social/@Gargron # any account URL |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
209 |
`, |
0 | 210 |
RunE: func(cmd *cobra.Command, args []string) error { |
211 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
212 |
}, |
|
213 |
} |
|
214 |
||
215 |
var accountFollowRequestsSubcommand = &cobra.Command{ |
|
216 |
Use: "follow-requests", |
|
217 |
Aliases: []string{"follow-request", "fr"}, |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
218 |
Short: "List, accept or deny a follow request", |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
219 |
Example: ` madonctl account follow-requests --list |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
220 |
madonctl account follow-requests --account-id X --accept |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
221 |
madonctl account follow-requests --account-id Y --reject`, |
0 | 222 |
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
|
223 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 224 |
}, |
225 |
} |
|
226 |
var accountFollowSubcommand = &cobra.Command{ |
|
227 |
Use: "follow", |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
228 |
Short: "Follow an account", |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
229 |
Example: `# Argument type can be set explicitly: |
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
230 |
madonctl account follow --account-id 1234 |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
231 |
madonctl account follow --remote Gargron@mastodon.social |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
232 |
|
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
233 |
# Or argument type can be guessed: |
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
234 |
madonctl account follow 4800 |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
235 |
madonctl account follow Gargron@mastodon.social --show-reblogs=false |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
236 |
madonctl account follow https://mastodon.social/@Gargron |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
237 |
`, |
0 | 238 |
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
|
239 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 240 |
}, |
241 |
} |
|
242 |
||
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
243 |
var accountUnfollowSubcommand = &cobra.Command{ |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
244 |
Use: "unfollow", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
245 |
Short: "Stop following an account", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
246 |
Example: ` madonctl account unfollow --account-id 1234 |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
247 |
|
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
248 |
Same usage as madonctl follow. |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
249 |
`, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
250 |
RunE: func(cmd *cobra.Command, args []string) error { |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
251 |
return accountSubcommandsRunE(cmd.Name(), args) |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
252 |
}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
253 |
} |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
254 |
|
0 | 255 |
var accountBlockSubcommand = &cobra.Command{ |
256 |
Use: "block", |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
257 |
Short: "Block the account", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
258 |
RunE: func(cmd *cobra.Command, args []string) error { |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
259 |
return accountSubcommandsRunE(cmd.Name(), args) |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
260 |
}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
261 |
} |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
262 |
|
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
263 |
var accountUnblockSubcommand = &cobra.Command{ |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
264 |
Use: "unblock", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
265 |
Short: "Unblock the account", |
0 | 266 |
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
|
267 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 268 |
}, |
269 |
} |
|
270 |
||
271 |
var accountMuteSubcommand = &cobra.Command{ |
|
272 |
Use: "mute", |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
273 |
Short: "Mute the account", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
274 |
RunE: func(cmd *cobra.Command, args []string) error { |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
275 |
return accountSubcommandsRunE(cmd.Name(), args) |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
276 |
}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
277 |
} |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
278 |
|
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
279 |
var accountUnmuteSubcommand = &cobra.Command{ |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
280 |
Use: "unmute", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
281 |
Short: "Unmute the account", |
0 | 282 |
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
|
283 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 284 |
}, |
285 |
} |
|
286 |
||
226
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
287 |
var accountPinSubcommand = &cobra.Command{ |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
288 |
Use: "pin", |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
289 |
Short: "Endorse (pin) the account", |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
290 |
Aliases: []string{"endorse"}, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
291 |
RunE: func(cmd *cobra.Command, args []string) error { |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
292 |
return accountSubcommandsRunE(cmd.Name(), args) |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
293 |
}, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
294 |
} |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
295 |
|
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
296 |
var accountUnpinSubcommand = &cobra.Command{ |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
297 |
Use: "unpin", |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
298 |
Short: "Cancel endorsement of an account", |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
299 |
Aliases: []string{"disavow"}, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
300 |
RunE: func(cmd *cobra.Command, args []string) error { |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
301 |
return accountSubcommandsRunE(cmd.Name(), args) |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
302 |
}, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
303 |
} |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
304 |
|
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
305 |
var accountListEndorsementsSubcommand = &cobra.Command{ |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
306 |
Use: "pinned", |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
307 |
Short: `Display the list of pinned (endorsed) accounts`, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
308 |
Aliases: []string{"list-endorsements", "get-endorsements"}, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
309 |
RunE: func(cmd *cobra.Command, args []string) error { |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
310 |
return accountSubcommandsRunE(cmd.Name(), args) |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
311 |
}, |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
312 |
} |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
313 |
|
0 | 314 |
var accountRelationshipsSubcommand = &cobra.Command{ |
315 |
Use: "relationships --account-ids ACC1,ACC2...", |
|
316 |
Short: "List relationships with the accounts", |
|
317 |
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
|
318 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 319 |
}, |
320 |
} |
|
321 |
||
322 |
var accountReportsSubcommand = &cobra.Command{ |
|
323 |
Use: "reports", |
|
324 |
Short: "List reports or report a user account", |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
325 |
Example: ` madonctl account reports --list |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
326 |
madonctl account reports --account-id ACCOUNT --status-ids ID... --comment TEXT`, |
0 | 327 |
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
|
328 |
return accountSubcommandsRunE(cmd.Name(), args) |
0 | 329 |
}, |
330 |
} |
|
331 |
||
6 | 332 |
var accountUpdateSubcommand = &cobra.Command{ |
333 |
Use: "update", |
|
334 |
Short: "Update connected user account", |
|
335 |
Long: `Update connected user account |
|
336 |
||
337 |
All flags are optional (set to an empty string if you want to delete a field). |
|
218
49d626ce0b01
account: Update online help wrt --avatar & --header flags
Mikael Berthe <mikael@lilotux.net>
parents:
209
diff
changeset
|
338 |
The options --avatar and --header should be paths to image files. |
6 | 339 |
|
340 |
Please note the avatar and header images cannot be removed, they can only be |
|
341 |
replaced.`, |
|
209
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
342 |
Example: ` madonctl account update --display-name "Mr President" |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
343 |
madonctl account update --note "I like madonctl" |
3772cc6b3d0a
accounts: Use singular form
Mikael Berthe <mikael@lilotux.net>
parents:
208
diff
changeset
|
344 |
madonctl account update --avatar happyface.png`, |
6 | 345 |
RunE: func(cmd *cobra.Command, args []string) error { |
346 |
return accountSubcommandsRunE(cmd.Name(), args) |
|
347 |
}, |
|
348 |
} |
|
349 |
||
0 | 350 |
// accountSubcommandsRunE is a generic function for status subcommands |
351 |
func accountSubcommandsRunE(subcmd string, args []string) error { |
|
352 |
opt := accountsOpts |
|
353 |
||
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
354 |
if len(args) > 1 { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
355 |
return errors.New("too many arguments") |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
356 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
357 |
|
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
358 |
userInArg := false |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
359 |
|
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
360 |
if len(args) == 1 { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
361 |
if len(args[0]) > 0 { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
362 |
userInArg = true |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
363 |
} else { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
364 |
return errors.New("invalid argument (empty)") |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
365 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
366 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
367 |
|
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
368 |
// Check account is provided in only one way |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
369 |
aCounter := 0 |
267 | 370 |
if opt.accountID != "" { |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
371 |
aCounter++ |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
372 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
373 |
if opt.accountUID != "" { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
374 |
aCounter++ |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
375 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
376 |
if opt.remoteUID != "" { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
377 |
aCounter++ |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
378 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
379 |
if userInArg { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
380 |
aCounter++ |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
381 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
382 |
|
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
383 |
if aCounter > 1 { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
384 |
return errors.New("too many account identifiers provided") |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
385 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
386 |
|
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
387 |
if userInArg { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
388 |
// Is the argument an account ID? |
267 | 389 |
if _, err := strconv.ParseInt(args[0], 10, 64); err == nil { |
390 |
opt.accountID = args[0] |
|
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
391 |
} else if strings.HasPrefix(args[0], "https://") || strings.HasPrefix(args[0], "http://") { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
392 |
// That is not a remote UID scheme |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
393 |
opt.accountUID = args[0] |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
394 |
} else if subcmd == "follow" { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
395 |
// For the follow API, got to be a remote UID... |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
396 |
opt.remoteUID = args[0] |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
397 |
// ... unless it's local (i.e. no '@' in the identifier)... |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
398 |
fid := strings.TrimLeft(args[0], "@") |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
399 |
if !strings.ContainsRune(fid, '@') { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
400 |
opt.accountUID = args[0] |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
401 |
opt.remoteUID = "" |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
402 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
403 |
} else { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
404 |
// Fall back to account UID |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
405 |
opt.accountUID = args[0] |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
406 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
407 |
} |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
408 |
|
16 | 409 |
if opt.accountUID != "" { |
267 | 410 |
if opt.accountID != "" { |
16 | 411 |
return errors.New("cannot use both account ID and UID") |
412 |
} |
|
413 |
// 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
|
414 |
var err error |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
415 |
if err = madonInit(true); err != nil { |
16 | 416 |
return err |
417 |
} |
|
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
418 |
opt.accountID, err = accountLookupUser(opt.accountUID) |
267 | 419 |
if err != nil || opt.accountID == "" { |
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
420 |
if err != nil { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
421 |
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
|
422 |
} else { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
423 |
errPrint("Cannot find user '%s'", opt.accountUID) |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
424 |
} |
16 | 425 |
os.Exit(1) |
426 |
} |
|
427 |
} |
|
428 |
||
0 | 429 |
switch subcmd { |
6 | 430 |
case "show", "search", "update": |
0 | 431 |
// These subcommands do not require an account ID |
226
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
432 |
case "favourites", "blocks", "mutes", "pinned": |
0 | 433 |
// Those subcommands can not use an account ID |
267 | 434 |
if opt.accountID != "" { |
0 | 435 |
return errors.New("useless account ID") |
436 |
} |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
437 |
case "follow", "unfollow": |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
438 |
// We need an account ID or a remote UID |
267 | 439 |
if opt.accountID == "" && opt.remoteUID == "" { |
0 | 440 |
return errors.New("missing account ID or URI") |
441 |
} |
|
267 | 442 |
if opt.accountID != "" && opt.remoteUID != "" { |
0 | 443 |
return errors.New("cannot use both account ID and URI") |
444 |
} |
|
271
c8b8b7cc8896
Remove deprecated flag (`--unset`)
Mikael Berthe <mikael@lilotux.net>
parents:
268
diff
changeset
|
445 |
if subcmd == "unfollow" && opt.accountID == "" { |
0 | 446 |
return errors.New("unfollowing requires an account ID") |
447 |
} |
|
448 |
case "follow-requests": |
|
449 |
if opt.list { |
|
450 |
if opt.acceptFR || opt.rejectFR { |
|
451 |
return errors.New("incompatible options") |
|
452 |
} |
|
453 |
} else { |
|
454 |
if !opt.acceptFR && !opt.rejectFR { // No flag |
|
455 |
return errors.New("missing parameter (--list, --accept or --reject)") |
|
456 |
} |
|
457 |
// This is a FR reply |
|
458 |
if opt.acceptFR && opt.rejectFR { |
|
459 |
return errors.New("incompatible options") |
|
460 |
} |
|
267 | 461 |
if opt.accountID == "" { |
0 | 462 |
return errors.New("missing account ID") |
463 |
} |
|
464 |
} |
|
465 |
case "relationships": |
|
267 | 466 |
if opt.accountID == "" && len(opt.accountIDs) == 0 { |
0 | 467 |
return errors.New("missing account IDs") |
468 |
} |
|
267 | 469 |
if opt.accountID != "" && len(opt.accountIDs) > 0 { |
0 | 470 |
return errors.New("incompatible options") |
471 |
} |
|
472 |
case "reports": |
|
473 |
if opt.list { |
|
474 |
break // No argument needed |
|
475 |
} |
|
267 | 476 |
if opt.accountID == "" || len(opt.statusIDs) == 0 || opt.comment == "" { |
0 | 477 |
return errors.New("missing parameter") |
478 |
} |
|
28
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
479 |
case "followers", "following", "statuses": |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
480 |
// If the user's account ID is missing, get it |
267 | 481 |
if opt.accountID == "" { |
28
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
482 |
// 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
|
483 |
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
|
484 |
return err |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
485 |
} |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
486 |
account, err := gClient.GetCurrentAccount() |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
487 |
if err != nil { |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
488 |
return err |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
489 |
} |
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
490 |
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
|
491 |
if verbose { |
4f12e5d4ef75
Display account ID in verbose mode when it is looked up
Mikael Berthe <mikael@lilotux.net>
parents:
28
diff
changeset
|
492 |
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
|
493 |
} |
28
79aa812c0dd2
Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
494 |
} |
0 | 495 |
default: |
496 |
// The other subcommands here require an account ID |
|
267 | 497 |
if opt.accountID == "" { |
0 | 498 |
return errors.New("missing account ID") |
499 |
} |
|
500 |
} |
|
501 |
||
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
502 |
var limOpts *madon.LimitParams |
267 | 503 |
if opt.all || opt.limit > 0 || opt.sinceID != "" || opt.maxID != "" { |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
504 |
limOpts = new(madon.LimitParams) |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
29
diff
changeset
|
505 |
limOpts.All = opt.all |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
506 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
507 |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
508 |
if opt.limit > 0 { |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
509 |
limOpts.Limit = int(opt.limit) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
510 |
} |
267 | 511 |
if opt.maxID != "" { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
512 |
limOpts.MaxID = opt.maxID |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
513 |
} |
267 | 514 |
if opt.sinceID != "" { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
515 |
limOpts.SinceID = opt.sinceID |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
516 |
} |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
517 |
|
0 | 518 |
// All account subcommands need to have signed in |
519 |
if err := madonInit(true); err != nil { |
|
520 |
return err |
|
521 |
} |
|
522 |
||
523 |
var obj interface{} |
|
524 |
var err error |
|
525 |
||
526 |
switch subcmd { |
|
527 |
case "show": |
|
528 |
var account *madon.Account |
|
267 | 529 |
if opt.accountID != "" { |
0 | 530 |
account, err = gClient.GetAccount(opt.accountID) |
531 |
} else { |
|
532 |
account, err = gClient.GetCurrentAccount() |
|
533 |
} |
|
534 |
obj = account |
|
535 |
case "search": |
|
536 |
var accountList []madon.Account |
|
184
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
537 |
accountList, err = gClient.SearchAccounts(strings.Join(args, " "), opt.following, limOpts) |
0 | 538 |
obj = accountList |
539 |
case "followers": |
|
540 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
} |
0 | 545 |
obj = accountList |
546 |
case "following": |
|
547 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
} |
0 | 552 |
obj = accountList |
553 |
case "statuses": |
|
554 |
var statusList []madon.Status |
|
180
9bcc6dc003fd
Add '--pinned' flag to madonctl account statuses
Mikael Berthe <mikael@lilotux.net>
parents:
178
diff
changeset
|
555 |
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
|
556 |
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
|
557 |
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
|
558 |
} |
0 | 559 |
obj = statusList |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
560 |
case "follow", "unfollow": |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
561 |
var relationship *madon.Relationship |
271
c8b8b7cc8896
Remove deprecated flag (`--unset`)
Mikael Berthe <mikael@lilotux.net>
parents:
268
diff
changeset
|
562 |
if subcmd == "unfollow" { |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
563 |
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
|
564 |
obj = relationship |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
565 |
break |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
566 |
} |
267 | 567 |
if opt.accountID == "" { |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
568 |
if opt.remoteUID != "" { |
205
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
569 |
// Remote account |
0 | 570 |
var account *madon.Account |
571 |
account, err = gClient.FollowRemoteAccount(opt.remoteUID) |
|
572 |
obj = account |
|
205
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
573 |
break |
0 | 574 |
} |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
575 |
return errors.New("error: no usable parameter") |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
576 |
} |
205
60f4c2acedfd
account follow: Add --show-reblogs flag
Mikael Berthe <mikael@lilotux.net>
parents:
196
diff
changeset
|
577 |
|
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
578 |
// Locally-known account |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
579 |
var followReblogs *bool |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
580 |
if accountFollowFlags.Lookup("show-reblogs").Changed { |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
581 |
// Set followReblogs as it's been explicitly requested |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
582 |
followReblogs = &opt.reblogs |
0 | 583 |
} |
208
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
584 |
relationship, err = gClient.FollowAccount(opt.accountID, followReblogs) |
7a830fed2ba3
madonctl account: Try to gues account ID type
Mikael Berthe <mikael@lilotux.net>
parents:
205
diff
changeset
|
585 |
obj = relationship |
0 | 586 |
case "follow-requests": |
587 |
if opt.list { |
|
588 |
var followRequests []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
589 |
followRequests, err = gClient.GetAccountFollowRequests(limOpts) |
267 | 590 |
if opt.accountID != "" { // Display a specific request |
160
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
591 |
var fRequest *madon.Account |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
592 |
for _, fr := range followRequests { |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
593 |
if fr.ID == opt.accountID { |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
594 |
fRequest = &fr |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
595 |
break |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
596 |
} |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
597 |
} |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
598 |
if fRequest != nil { |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
599 |
followRequests = []madon.Account{*fRequest} |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
600 |
} else { |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
601 |
followRequests = []madon.Account{} |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
602 |
} |
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
603 |
} else { |
167
1341bacd01c9
Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents:
160
diff
changeset
|
604 |
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
|
605 |
followRequests = followRequests[:opt.keep] |
160
452865b363fb
Allow accounts follow-requests --account-id X --list
Mikael Berthe <mikael@lilotux.net>
parents:
149
diff
changeset
|
606 |
} |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
12
diff
changeset
|
607 |
} |
0 | 608 |
obj = followRequests |
609 |
} else { |
|
610 |
err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR) |
|
611 |
} |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
612 |
case "block", "unblock": |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
613 |
var relationship *madon.Relationship |
271
c8b8b7cc8896
Remove deprecated flag (`--unset`)
Mikael Berthe <mikael@lilotux.net>
parents:
268
diff
changeset
|
614 |
if subcmd == "unblock" { |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
615 |
relationship, err = gClient.UnblockAccount(opt.accountID) |
0 | 616 |
} else { |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
617 |
relationship, err = gClient.BlockAccount(opt.accountID) |
0 | 618 |
} |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
619 |
obj = relationship |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
226
diff
changeset
|
620 |
case "mute", "unmute": |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
621 |
var relationship *madon.Relationship |
271
c8b8b7cc8896
Remove deprecated flag (`--unset`)
Mikael Berthe <mikael@lilotux.net>
parents:
268
diff
changeset
|
622 |
if subcmd == "unmute" { |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
623 |
relationship, err = gClient.UnmuteAccount(opt.accountID) |
0 | 624 |
} else { |
182
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
625 |
var muteNotif *bool |
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
626 |
if accountMuteFlags.Lookup("notifications").Changed { |
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
627 |
muteNotif = &opt.muteNotifications |
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
628 |
} |
842f6cea448f
madonctl accounts mute: Add '--notifications' flag
Mikael Berthe <mikael@lilotux.net>
parents:
180
diff
changeset
|
629 |
relationship, err = gClient.MuteAccount(opt.accountID, muteNotif) |
0 | 630 |
} |
145
0f6b8411ad36
Sync with Madon library 1.6: Some calls return a Relationship entity
Mikael Berthe <mikael@lilotux.net>
parents:
113
diff
changeset
|
631 |
obj = relationship |
226
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
632 |
case "pin", "unpin": |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
633 |
var relationship *madon.Relationship |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
634 |
if subcmd == "unpin" { |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
635 |
relationship, err = gClient.UnpinAccount(opt.accountID) |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
636 |
} else { |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
637 |
relationship, err = gClient.PinAccount(opt.accountID) |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
638 |
} |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
639 |
obj = relationship |
0 | 640 |
case "favourites": |
641 |
var statusList []madon.Status |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
642 |
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
|
643 |
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
|
644 |
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
|
645 |
} |
0 | 646 |
obj = statusList |
647 |
case "blocks": |
|
648 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
649 |
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
|
650 |
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
|
651 |
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
|
652 |
} |
0 | 653 |
obj = accountList |
654 |
case "mutes": |
|
655 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
656 |
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
|
657 |
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
|
658 |
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
|
659 |
} |
0 | 660 |
obj = accountList |
226
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
661 |
case "pinned": |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
662 |
var accountList []madon.Account |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
663 |
accountList, err = gClient.GetEndorsements(limOpts) |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
664 |
if opt.keep > 0 && len(accountList) > int(opt.keep) { |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
665 |
accountList = accountList[:opt.keep] |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
666 |
} |
5df927fa87ca
Add account endorsement support
Mikael Berthe <mikael@lilotux.net>
parents:
224
diff
changeset
|
667 |
obj = accountList |
0 | 668 |
case "relationships": |
267 | 669 |
var ids []madon.ActivityID |
0 | 670 |
ids, err = splitIDs(opt.accountIDs) |
671 |
if err != nil { |
|
672 |
return errors.New("cannot parse account IDs") |
|
673 |
} |
|
267 | 674 |
if opt.accountID != "" { // Allow --account-id |
675 |
ids = []madon.ActivityID{opt.accountID} |
|
0 | 676 |
} |
677 |
if len(ids) < 1 { |
|
678 |
return errors.New("missing account IDs") |
|
679 |
} |
|
680 |
var relationships []madon.Relationship |
|
681 |
relationships, err = gClient.GetAccountRelationships(ids) |
|
682 |
obj = relationships |
|
683 |
case "reports": |
|
684 |
if opt.list { |
|
685 |
var reports []madon.Report |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
686 |
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
|
687 |
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
|
688 |
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
|
689 |
} |
0 | 690 |
obj = reports |
691 |
break |
|
692 |
} |
|
693 |
// Send a report |
|
267 | 694 |
var ids []madon.ActivityID |
0 | 695 |
ids, err = splitIDs(opt.statusIDs) |
696 |
if err != nil { |
|
697 |
return errors.New("cannot parse status IDs") |
|
698 |
} |
|
699 |
if len(ids) < 1 { |
|
700 |
return errors.New("missing status IDs") |
|
701 |
} |
|
702 |
var report *madon.Report |
|
703 |
report, err = gClient.ReportUser(opt.accountID, ids, opt.comment) |
|
704 |
obj = report |
|
6 | 705 |
case "update": |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
706 |
var updateParams madon.UpdateAccountParams |
223
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
707 |
var source *madon.SourceParams |
6 | 708 |
change := false |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
709 |
|
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
710 |
if accountUpdateFlags.Lookup("display-name").Changed { |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
711 |
updateParams.DisplayName = &opt.displayName |
6 | 712 |
change = true |
713 |
} |
|
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
714 |
if accountUpdateFlags.Lookup("note").Changed { |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
715 |
updateParams.Note = &opt.note |
6 | 716 |
change = true |
717 |
} |
|
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
718 |
if accountUpdateFlags.Lookup("avatar").Changed { |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
719 |
updateParams.AvatarImagePath = &opt.avatar |
6 | 720 |
change = true |
721 |
} |
|
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
722 |
if accountUpdateFlags.Lookup("header").Changed { |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
723 |
updateParams.HeaderImagePath = &opt.header |
6 | 724 |
change = true |
725 |
} |
|
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
726 |
if accountUpdateFlags.Lookup("locked").Changed { |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
727 |
updateParams.Locked = &opt.locked |
178
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
728 |
change = true |
15d211137c20
Add '--locked' flag to account update subcommand
Mikael Berthe <mikael@lilotux.net>
parents:
168
diff
changeset
|
729 |
} |
222
e93d9c738273
Add '--bot' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
220
diff
changeset
|
730 |
if accountUpdateFlags.Lookup("bot").Changed { |
e93d9c738273
Add '--bot' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
220
diff
changeset
|
731 |
updateParams.Bot = &opt.bot |
e93d9c738273
Add '--bot' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
220
diff
changeset
|
732 |
change = true |
e93d9c738273
Add '--bot' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
220
diff
changeset
|
733 |
} |
223
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
734 |
if accountUpdateFlags.Lookup("default-language").Changed { |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
735 |
if source == nil { |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
736 |
source = &madon.SourceParams{} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
737 |
} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
738 |
source.Language = &opt.defaultLanguage |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
739 |
change = true |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
740 |
} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
741 |
if accountUpdateFlags.Lookup("default-privacy").Changed { |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
742 |
if source == nil { |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
743 |
source = &madon.SourceParams{} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
744 |
} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
745 |
source.Privacy = &opt.defaultPrivacy |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
746 |
change = true |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
747 |
} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
748 |
if accountUpdateFlags.Lookup("default-sensitive").Changed { |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
749 |
if source == nil { |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
750 |
source = &madon.SourceParams{} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
751 |
} |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
752 |
source.Sensitive = &opt.defaultSensitive |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
753 |
change = true |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
754 |
} |
224
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
755 |
if accountUpdateFlags.Lookup("profile-field").Changed { |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
756 |
var fa = []madon.Field{} |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
757 |
for _, f := range opt.profileFields { |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
758 |
kv := strings.SplitN(f, "=", 2) |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
759 |
if len(kv) != 2 { |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
760 |
return errors.New("cannot parse field") |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
761 |
} |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
762 |
fa = append(fa, madon.Field{Name: kv[0], Value: kv[1]}) |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
763 |
} |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
764 |
updateParams.FieldsAttributes = &fa |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
765 |
change = true |
d33a2c4fdfbf
Add '--profile-field' flag to madonctl account update
Mikael Berthe <mikael@lilotux.net>
parents:
223
diff
changeset
|
766 |
} |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
767 |
|
6 | 768 |
if !change { // We want at least one update |
769 |
return errors.New("missing parameters") |
|
770 |
} |
|
771 |
||
223
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
772 |
updateParams.Source = source |
0412068a9445
madonctl account update: Add support for updating 'source' parameters
Mikael Berthe <mikael@lilotux.net>
parents:
222
diff
changeset
|
773 |
|
6 | 774 |
var account *madon.Account |
220
08a2ee738117
Update calls to madon's PostStatus & UpdateAccount
Mikael Berthe <mikael@lilotux.net>
parents:
218
diff
changeset
|
775 |
account, err = gClient.UpdateAccount(updateParams) |
6 | 776 |
obj = account |
0 | 777 |
default: |
778 |
return errors.New("accountSubcommand: internal error") |
|
779 |
} |
|
780 |
||
781 |
if err != nil { |
|
782 |
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
|
783 |
os.Exit(1) |
0 | 784 |
} |
785 |
if obj == nil { |
|
786 |
return nil |
|
787 |
} |
|
788 |
||
789 |
p, err := getPrinter() |
|
790 |
if err != nil { |
|
81
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
791 |
errPrint("Error: %s", err.Error()) |
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
792 |
os.Exit(1) |
0 | 793 |
} |
110 | 794 |
return p.printObj(obj) |
0 | 795 |
} |
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
796 |
|
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
797 |
// 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
|
798 |
// 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
|
799 |
// it will use the accounts/search API. |
267 | 800 |
func accountLookupUser(user string) (madon.ActivityID, error) { |
801 |
var accID madon.ActivityID |
|
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
802 |
|
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
803 |
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
|
804 |
res, err := gClient.Search(user, true) |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
805 |
if err != nil { |
267 | 806 |
return "", err |
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
807 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
808 |
if res != nil { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
809 |
if len(res.Accounts) > 1 { |
267 | 810 |
return "", errors.New("several results") |
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
811 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
812 |
if len(res.Accounts) == 1 { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
813 |
accID = res.Accounts[0].ID |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
814 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
815 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
816 |
} else { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
817 |
// Remove leading '@' |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
818 |
user = strings.TrimLeft(user, "@") |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
819 |
|
184
a685b52c2ddf
account search: Add flag '--following'
Mikael Berthe <mikael@lilotux.net>
parents:
182
diff
changeset
|
820 |
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
|
821 |
if err != nil { |
267 | 822 |
return "", err |
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
823 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
824 |
for _, u := range accList { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
825 |
if u.Acct == user { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
826 |
accID = u.ID |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
827 |
break |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
828 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
829 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
830 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
831 |
|
267 | 832 |
if accID == "" { |
833 |
return "", errors.New("user not found") |
|
102
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
834 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
835 |
if verbose { |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
836 |
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
|
837 |
} |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
838 |
return accID, nil |
84ad56b643c8
Allow HTTP URLs in --user-id
Mikael Berthe <mikael@lilotux.net>
parents:
81
diff
changeset
|
839 |
} |