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