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