cmd/accounts.go
author Mikael Berthe <mikael@lilotux.net>
Sat, 29 Apr 2017 13:54:04 +0200
changeset 28 79aa812c0dd2
parent 22 5778b09bc6fe
child 29 4f12e5d4ef75
permissions -rw-r--r--
Make account ID optional for accounts followers|following|statuses If the ID is missing, the account ID of the connected user is looked up.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
// Copyright © 2017 Mikael Berthe <mikael@lilotux.net>
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 (
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
	"errors"
16
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    10
	"os"
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
	"github.com/spf13/cobra"
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    14
	flag "github.com/spf13/pflag"
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
	"github.com/McKael/madon"
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
)
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
var accountsOpts struct {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    20
	accountID                 int
16
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    21
	accountUID                string
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
    22
	unset                     bool   // TODO remove eventually?
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
    23
	limit, sinceID, maxID     uint   // Limit the results
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
	onlyMedia, excludeReplies bool   // For acccount statuses
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
	remoteUID                 string // For account follow
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
	acceptFR, rejectFR        bool   // For account follow_requests
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
	list                      bool   // For account follow_requests/reports
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
	accountIDs                string // For account relationships
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    29
	statusIDs                 string // For account reports
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
	comment                   string // For account reports
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
	show                      bool   // For account reports
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    32
	displayName, note         string // For account update
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    33
	avatar, header            string // For account update
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    36
var updateFlags *flag.FlagSet
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    37
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    38
func init() {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
	RootCmd.AddCommand(accountsCmd)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
	// Subcommands
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
	accountsCmd.AddCommand(accountSubcommands...)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
	// Global flags
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
	accountsCmd.PersistentFlags().IntVarP(&accountsOpts.accountID, "account-id", "a", 0, "Account ID number")
16
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    46
	accountsCmd.PersistentFlags().StringVarP(&accountsOpts.accountUID, "user-id", "u", "", "Account user ID")
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
    47
	accountsCmd.PersistentFlags().UintVarP(&accountsOpts.limit, "limit", "l", 0, "Limit number of results")
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
    48
	accountsCmd.PersistentFlags().UintVar(&accountsOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
    49
	accountsCmd.PersistentFlags().UintVar(&accountsOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
	// Subcommand flags
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    52
	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
    53
	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
    54
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    55
	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    56
	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
    57
	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
    58
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    59
	accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    62
	accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)")
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
	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
    65
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    66
	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
    67
	accountReportsSubcommand.Flags().StringVar(&accountsOpts.comment, "comment", "", "Report comment")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    68
	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
    69
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    70
	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.displayName, "display-name", "", "User display name")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    71
	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
    72
	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.avatar, "avatar", "", "User avatar image")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    73
	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.header, "header", "", "User header image")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    74
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    75
	// This one will be used to check if the options were explicitely set or not
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    76
	updateFlags = accountUpdateSubcommand.Flags()
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    77
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    78
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    79
// accountsCmd represents the accounts command
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    80
// This command does nothing without a subcommand
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    81
var accountsCmd = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    82
	Use:     "accounts [--account-id ID] subcommand",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    83
	Aliases: []string{"account"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    84
	Short:   "Account-related functions",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    85
	//Long:    `TBW...`, // TODO
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    86
	//PersistentPreRunE: func(cmd *cobra.Command, args []string) error {},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    87
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    88
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    89
// Note: Some account subcommands are not defined in this file.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    90
var accountSubcommands = []*cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    91
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    92
		Use: "show",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    93
		Long: `Displays the details about the requested account.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    94
If no account ID is specified, the current user account is used.`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    95
		Aliases: []string{"display"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    96
		Short:   "Display the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    97
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    98
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    99
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   100
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   101
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   102
		Use:   "followers",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   103
		Short: "Display the accounts following the specified account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   104
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   105
			return accountSubcommandsRunE(cmd.Name(), args)
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
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   108
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   109
		Use:   "following",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   110
		Short: "Display the accounts followed by the specified account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   111
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   112
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   113
		},
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
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   116
		Use:     "favourites",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   117
		Aliases: []string{"favorites", "favourited", "favorited"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   118
		Short:   "Display the user's favourites",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   119
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   120
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   121
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   122
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   123
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   124
		Use:     "blocks",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   125
		Aliases: []string{"blocked"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   126
		Short:   "Display the user's blocked accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   127
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   128
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   129
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   130
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   131
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   132
		Use:     "mutes",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   133
		Aliases: []string{"muted"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   134
		Short:   "Display the user's muted accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   135
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   136
			return accountSubcommandsRunE(cmd.Name(), args)
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
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   139
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   140
		Use:   "search TEXT",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   141
		Short: "Search for user accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   142
		Long: `Search for user accounts.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   143
The server will lookup an account remotely if the search term is in the
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   144
username@domain format and not yet in the database.`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   145
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   146
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   147
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   148
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   149
	accountStatusesSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   150
	accountFollowRequestsSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   151
	accountFollowSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   152
	accountBlockSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   153
	accountMuteSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   154
	accountRelationshipsSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   155
	accountReportsSubcommand,
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   156
	accountUpdateSubcommand,
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   157
}
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
var accountStatusesSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   160
	Use:     "statuses",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   161
	Aliases: []string{"st"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   162
	Short:   "Display the account statuses",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   163
	RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   164
		return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   165
	},
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
var accountFollowRequestsSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   169
	Use:     "follow-requests",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   170
	Aliases: []string{"follow-request", "fr"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   171
	Example: `  madonctl accounts follow-requests --list
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   172
  madonctl accounts follow-requests --account-id X --accept
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   173
  madonctl accounts follow-requests --account-id Y --reject`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   174
	Short: "List, accept or deny a follow request",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   175
	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
   176
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   177
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   178
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   179
var accountFollowSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   180
	Use:   "follow",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   181
	Short: "Follow or unfollow the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   182
	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
   183
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   184
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   185
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   186
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   187
var accountBlockSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   188
	Use:   "block",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   189
	Short: "Block or unblock the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   190
	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
   191
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   192
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   193
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   194
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   195
var accountMuteSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   196
	Use:   "mute",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   197
	Short: "Mute or unmute the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   198
	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
   199
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   200
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   201
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   202
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   203
var accountRelationshipsSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   204
	Use:   "relationships --account-ids ACC1,ACC2...",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   205
	Short: "List relationships with the accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   206
	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
   207
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   208
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   209
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   210
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   211
var accountReportsSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   212
	Use:   "reports",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   213
	Short: "List reports or report a user account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   214
	Example: `  madonctl accounts reports --list
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   215
  madonctl accounts reports --account-id ACCOUNT --status-ids ID... --comment TEXT`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   216
	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
   217
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   218
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   219
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   220
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   221
var accountUpdateSubcommand = &cobra.Command{
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   222
	Use:   "update",
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   223
	Short: "Update connected user account",
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   224
	Long: `Update connected user account
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   225
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   226
All flags are optional (set to an empty string if you want to delete a field).
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   227
The flags --avatar and --header can be paths to image files or base64-encoded
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   228
images (see Mastodon API specifications for the details).
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   229
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   230
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
   231
replaced.`,
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   232
	Example: `  madonctl accounts update --display-name "Mr President"
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   233
  madonctl accounts update --note "I like madonctl"
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   234
  madonctl accounts update --avatar happyface.png`,
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   235
	RunE: func(cmd *cobra.Command, args []string) error {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   236
		return accountSubcommandsRunE(cmd.Name(), args)
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   237
	},
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   238
}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   239
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   240
// accountSubcommandsRunE is a generic function for status subcommands
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   241
func accountSubcommandsRunE(subcmd string, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   242
	opt := accountsOpts
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   243
16
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   244
	if opt.accountUID != "" {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   245
		if opt.accountID > 0 {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   246
			return errors.New("cannot use both account ID and UID")
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   247
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   248
		// Remove leading '@'
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   249
		opt.accountUID = strings.TrimLeft(opt.accountUID, "@")
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   250
		// Sign in early to look the user id up
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   251
		if err := madonInit(true); err != nil {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   252
			return err
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   253
		}
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   254
		accList, err := gClient.SearchAccounts(opt.accountUID, &madon.LimitParams{Limit: 2})
16
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   255
		if err != nil || len(accList) < 1 {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   256
			errPrint("Cannot find user '%s': %v", opt.accountUID, err)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   257
			os.Exit(1)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   258
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   259
		for _, u := range accList {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   260
			if u.Acct == opt.accountUID {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   261
				opt.accountID = u.ID
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   262
				break
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   263
			}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   264
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   265
		if opt.accountID < 1 {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   266
			errPrint("Cannot find user '%s'", opt.accountUID)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   267
			os.Exit(1)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   268
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   269
		if verbose {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   270
			errPrint("User '%s' is account ID %d", opt.accountUID, opt.accountID)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   271
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   272
	}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   273
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   274
	switch subcmd {
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   275
	case "show", "search", "update":
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   276
		// These subcommands do not require an account ID
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   277
	case "favourites", "blocks", "mutes":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   278
		// Those subcommands can not use an account ID
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   279
		if opt.accountID > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   280
			return errors.New("useless account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   281
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   282
	case "follow":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   283
		if opt.accountID < 1 && opt.remoteUID == "" {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   284
			return errors.New("missing account ID or URI")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   285
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   286
		if opt.accountID > 0 && opt.remoteUID != "" {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   287
			return errors.New("cannot use both account ID and URI")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   288
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   289
		if opt.unset && opt.accountID < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   290
			return errors.New("unfollowing requires an account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   291
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   292
	case "follow-requests":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   293
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   294
			if opt.acceptFR || opt.rejectFR {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   295
				return errors.New("incompatible options")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   296
			}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   297
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   298
			if !opt.acceptFR && !opt.rejectFR { // No flag
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   299
				return errors.New("missing parameter (--list, --accept or --reject)")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   300
			}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   301
			// This is a FR reply
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   302
			if opt.acceptFR && opt.rejectFR {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   303
				return errors.New("incompatible options")
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
			if opt.accountID < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   306
				return errors.New("missing account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   307
			}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   308
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   309
	case "relationships":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   310
		if opt.accountID < 1 && len(opt.accountIDs) == 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   311
			return errors.New("missing account IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   312
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   313
		if opt.accountID > 0 && len(opt.accountIDs) > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   314
			return errors.New("incompatible options")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   315
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   316
	case "reports":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   317
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   318
			break // No argument needed
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   319
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   320
		if opt.accountID < 1 || len(opt.statusIDs) == 0 || opt.comment == "" {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   321
			return errors.New("missing parameter")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   322
		}
28
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   323
	case "followers", "following", "statuses":
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   324
		// 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
   325
		if opt.accountID < 1 {
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   326
			// 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
   327
			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
   328
				return err
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   329
			}
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   330
			account, err := gClient.GetCurrentAccount()
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   331
			if err != nil {
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   332
				return err
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   333
			}
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   334
			opt.accountID = account.ID
79aa812c0dd2 Make account ID optional for accounts followers|following|statuses
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   335
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   336
	default:
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   337
		// The other subcommands here require an account ID
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   338
		if opt.accountID < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   339
			return errors.New("missing account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   340
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   341
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   342
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   343
	var limOpts *madon.LimitParams
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   344
	if opt.limit > 0 || opt.sinceID > 0 || opt.maxID > 0 {
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   345
		limOpts = new(madon.LimitParams)
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   346
	}
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   347
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   348
	if opt.limit > 0 {
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   349
		limOpts.Limit = int(opt.limit)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   350
	}
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   351
	if opt.maxID > 0 {
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   352
		limOpts.MaxID = int(opt.maxID)
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   353
	}
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   354
	if opt.sinceID > 0 {
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   355
		limOpts.SinceID = int(opt.sinceID)
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   356
	}
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   357
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   358
	// All account subcommands need to have signed in
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   359
	if err := madonInit(true); err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   360
		return err
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   361
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   362
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   363
	var obj interface{}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   364
	var err error
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   365
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   366
	switch subcmd {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   367
	case "show":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   368
		var account *madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   369
		if opt.accountID > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   370
			account, err = gClient.GetAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   371
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   372
			account, err = gClient.GetCurrentAccount()
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   373
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   374
		obj = account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   375
	case "search":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   376
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   377
		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), limOpts)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   378
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   379
	case "followers":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   380
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   381
		accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   382
		if opt.limit > 0 && len(accountList) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   383
			accountList = accountList[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   384
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   385
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   386
	case "following":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   387
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   388
		accountList, err = gClient.GetAccountFollowing(opt.accountID, limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   389
		if opt.limit > 0 && len(accountList) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   390
			accountList = accountList[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   391
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   392
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   393
	case "statuses":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   394
		var statusList []madon.Status
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   395
		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies, limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   396
		if opt.limit > 0 && len(statusList) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   397
			statusList = statusList[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   398
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   399
		obj = statusList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   400
	case "follow":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   401
		if opt.unset {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   402
			err = gClient.UnfollowAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   403
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   404
			if opt.accountID > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   405
				err = gClient.FollowAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   406
			} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   407
				var account *madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   408
				account, err = gClient.FollowRemoteAccount(opt.remoteUID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   409
				obj = account
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
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   412
	case "follow-requests":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   413
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   414
			var followRequests []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   415
			followRequests, err = gClient.GetAccountFollowRequests(limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   416
			if opt.limit > 0 && len(followRequests) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   417
				followRequests = followRequests[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   418
			}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   419
			obj = followRequests
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   420
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   421
			err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   422
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   423
	case "block":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   424
		if opt.unset {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   425
			err = gClient.UnblockAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   426
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   427
			err = gClient.BlockAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   428
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   429
	case "mute":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   430
		if opt.unset {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   431
			err = gClient.UnmuteAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   432
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   433
			err = gClient.MuteAccount(opt.accountID)
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
	case "favourites":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   436
		var statusList []madon.Status
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   437
		statusList, err = gClient.GetFavourites(limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   438
		if opt.limit > 0 && len(statusList) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   439
			statusList = statusList[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   440
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   441
		obj = statusList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   442
	case "blocks":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   443
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   444
		accountList, err = gClient.GetBlockedAccounts(limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   445
		if opt.limit > 0 && len(accountList) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   446
			accountList = accountList[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   447
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   448
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   449
	case "mutes":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   450
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   451
		accountList, err = gClient.GetMutedAccounts(limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   452
		if opt.limit > 0 && len(accountList) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   453
			accountList = accountList[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   454
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   455
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   456
	case "relationships":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   457
		var ids []int
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   458
		ids, err = splitIDs(opt.accountIDs)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   459
		if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   460
			return errors.New("cannot parse account IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   461
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   462
		if opt.accountID > 0 { // Allow --account-id
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   463
			ids = []int{opt.accountID}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   464
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   465
		if len(ids) < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   466
			return errors.New("missing account IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   467
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   468
		var relationships []madon.Relationship
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   469
		relationships, err = gClient.GetAccountRelationships(ids)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   470
		obj = relationships
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   471
	case "reports":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   472
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   473
			var reports []madon.Report
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   474
			reports, err = gClient.GetReports(limOpts)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 16
diff changeset
   475
			if opt.limit > 0 && len(reports) > int(opt.limit) {
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   476
				reports = reports[:opt.limit]
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   477
			}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   478
			obj = reports
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   479
			break
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   480
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   481
		// Send a report
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   482
		var ids []int
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   483
		ids, err = splitIDs(opt.statusIDs)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   484
		if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   485
			return errors.New("cannot parse status IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   486
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   487
		if len(ids) < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   488
			return errors.New("missing status IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   489
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   490
		var report *madon.Report
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   491
		report, err = gClient.ReportUser(opt.accountID, ids, opt.comment)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   492
		obj = report
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   493
	case "update":
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   494
		var dn, note, avatar, header *string
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   495
		change := false
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   496
		if updateFlags.Lookup("display-name").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   497
			dn = &opt.displayName
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   498
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   499
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   500
		if updateFlags.Lookup("note").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   501
			note = &opt.note
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   502
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   503
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   504
		if updateFlags.Lookup("avatar").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   505
			avatar = &opt.avatar
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   506
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   507
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   508
		if updateFlags.Lookup("header").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   509
			header = &opt.header
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   510
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   511
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   512
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   513
		if !change { // We want at least one update
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   514
			return errors.New("missing parameters")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   515
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   516
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   517
		var account *madon.Account
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   518
		account, err = gClient.UpdateAccount(dn, note, avatar, header)
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   519
		obj = account
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   520
	default:
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   521
		return errors.New("accountSubcommand: internal error")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   522
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   523
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   524
	if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   525
		errPrint("Error: %s", err.Error())
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   526
		return nil
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   527
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   528
	if obj == nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   529
		return nil
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   530
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   531
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   532
	p, err := getPrinter()
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   533
	if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   534
		return err
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   535
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   536
	return p.PrintObj(obj, nil, "")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   537
}