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