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