cmd/accounts.go
author Mikael Berthe <mikael@lilotux.net>
Tue, 25 Apr 2017 00:05:21 +0200
changeset 16 8939959991b3
parent 13 f862af8faf17
child 20 b0ccc09f07a2
permissions -rw-r--r--
accounts: add --user-id Look up the requested user ID and use it in place of --account-id. Currently the UID should match exactly the account's Acct field in order to avoid false positives.
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?
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
    23
	limit                     uint   // Limit the number of 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")
0
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
	// Subcommand flags
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
	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
    51
	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
    52
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    53
	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    54
	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
    55
	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
    56
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    57
	accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    58
	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    59
	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
	accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    62
	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
    63
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    64
	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
    65
	accountReportsSubcommand.Flags().StringVar(&accountsOpts.comment, "comment", "", "Report comment")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    66
	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
    67
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    68
	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.displayName, "display-name", "", "User display name")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    69
	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
    70
	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.avatar, "avatar", "", "User avatar image")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    71
	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.header, "header", "", "User header image")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    72
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    73
	// 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
    74
	updateFlags = accountUpdateSubcommand.Flags()
0
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    77
// accountsCmd represents the accounts command
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    78
// This command does nothing without a subcommand
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    79
var accountsCmd = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    80
	Use:     "accounts [--account-id ID] subcommand",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    81
	Aliases: []string{"account"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    82
	Short:   "Account-related functions",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    83
	//Long:    `TBW...`, // TODO
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    84
	//PersistentPreRunE: func(cmd *cobra.Command, args []string) error {},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    85
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    86
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    87
// Note: Some account subcommands are not defined in this file.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    88
var accountSubcommands = []*cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    89
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    90
		Use: "show",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    91
		Long: `Displays the details about the requested account.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    92
If no account ID is specified, the current user account is used.`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    93
		Aliases: []string{"display"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    94
		Short:   "Display the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    95
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    96
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    97
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    98
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    99
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   100
		Use:   "followers",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   101
		Short: "Display the accounts following the specified account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   102
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   103
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   104
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   105
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   106
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   107
		Use:   "following",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   108
		Short: "Display the accounts followed by the specified account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   109
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   110
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   111
		},
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
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   114
		Use:     "favourites",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   115
		Aliases: []string{"favorites", "favourited", "favorited"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   116
		Short:   "Display the user's favourites",
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:     "blocks",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   123
		Aliases: []string{"blocked"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   124
		Short:   "Display the user's blocked accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   125
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   126
			return accountSubcommandsRunE(cmd.Name(), args)
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
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   129
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   130
		Use:     "mutes",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   131
		Aliases: []string{"muted"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   132
		Short:   "Display the user's muted accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   133
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   134
			return accountSubcommandsRunE(cmd.Name(), args)
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
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   137
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   138
		Use:   "search TEXT",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   139
		Short: "Search for user accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   140
		Long: `Search for user accounts.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   141
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
   142
username@domain format and not yet in the database.`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   143
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   144
			return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   145
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   146
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   147
	accountStatusesSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   148
	accountFollowRequestsSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   149
	accountFollowSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   150
	accountBlockSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   151
	accountMuteSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   152
	accountRelationshipsSubcommand,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   153
	accountReportsSubcommand,
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   154
	accountUpdateSubcommand,
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   155
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   156
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   157
var accountStatusesSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   158
	Use:     "statuses",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   159
	Aliases: []string{"st"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   160
	Short:   "Display the account statuses",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   161
	RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   162
		return accountSubcommandsRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   163
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   164
}
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
var accountFollowRequestsSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   167
	Use:     "follow-requests",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   168
	Aliases: []string{"follow-request", "fr"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   169
	Example: `  madonctl accounts follow-requests --list
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   170
  madonctl accounts follow-requests --account-id X --accept
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   171
  madonctl accounts follow-requests --account-id Y --reject`,
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   172
	Short: "List, accept or deny a follow request",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   173
	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
   174
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   175
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   176
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   177
var accountFollowSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   178
	Use:   "follow",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   179
	Short: "Follow or unfollow the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   180
	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
   181
		return accountSubcommandsRunE(cmd.Name(), args)
0
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   185
var accountBlockSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   186
	Use:   "block",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   187
	Short: "Block or unblock the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   188
	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
   189
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   190
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   191
}
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
var accountMuteSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   194
	Use:   "mute",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   195
	Short: "Mute or unmute the account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   196
	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
   197
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   198
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   199
}
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
var accountRelationshipsSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   202
	Use:   "relationships --account-ids ACC1,ACC2...",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   203
	Short: "List relationships with the accounts",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   204
	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
   205
		return accountSubcommandsRunE(cmd.Name(), args)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   206
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   207
}
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
var accountReportsSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   210
	Use:   "reports",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   211
	Short: "List reports or report a user account",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   212
	Example: `  madonctl accounts reports --list
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   213
  madonctl accounts reports --account-id ACCOUNT --status-ids ID... --comment TEXT`,
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
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   219
var accountUpdateSubcommand = &cobra.Command{
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   220
	Use:   "update",
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   221
	Short: "Update connected user account",
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   222
	Long: `Update connected user account
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   223
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   224
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
   225
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
   226
images (see Mastodon API specifications for the details).
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   227
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   228
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
   229
replaced.`,
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   230
	Example: `  madonctl accounts update --display-name "Mr President"
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   231
  madonctl accounts update --note "I like madonctl"
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   232
  madonctl accounts update --avatar happyface.png`,
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   233
	RunE: func(cmd *cobra.Command, args []string) error {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   234
		return accountSubcommandsRunE(cmd.Name(), args)
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   235
	},
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   236
}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   237
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   238
// accountSubcommandsRunE is a generic function for status subcommands
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   239
func accountSubcommandsRunE(subcmd string, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   240
	opt := accountsOpts
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   241
16
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   242
	if opt.accountUID != "" {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   243
		if opt.accountID > 0 {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   244
			return errors.New("cannot use both account ID and UID")
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   245
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   246
		// Remove leading '@'
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   247
		opt.accountUID = strings.TrimLeft(opt.accountUID, "@")
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   248
		// Sign in early to look the user id up
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   249
		if err := madonInit(true); err != nil {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   250
			return err
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   251
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   252
		accList, err := gClient.SearchAccounts(opt.accountUID, 2)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   253
		if err != nil || len(accList) < 1 {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   254
			errPrint("Cannot find user '%s': %v", opt.accountUID, err)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   255
			os.Exit(1)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   256
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   257
		for _, u := range accList {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   258
			if u.Acct == opt.accountUID {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   259
				opt.accountID = u.ID
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   260
				break
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   261
			}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   262
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   263
		if opt.accountID < 1 {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   264
			errPrint("Cannot find user '%s'", opt.accountUID)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   265
			os.Exit(1)
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   266
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   267
		if verbose {
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   268
			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
   269
		}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   270
	}
8939959991b3 accounts: add --user-id
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   271
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   272
	switch subcmd {
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   273
	case "show", "search", "update":
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   274
		// These subcommands do not require an account ID
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   275
	case "favourites", "blocks", "mutes":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   276
		// Those subcommands can not use an account ID
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   277
		if opt.accountID > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   278
			return errors.New("useless account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   279
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   280
	case "follow":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   281
		if opt.accountID < 1 && opt.remoteUID == "" {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   282
			return errors.New("missing account ID or URI")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   283
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   284
		if opt.accountID > 0 && opt.remoteUID != "" {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   285
			return errors.New("cannot use both account ID and URI")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   286
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   287
		if opt.unset && opt.accountID < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   288
			return errors.New("unfollowing requires an account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   289
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   290
	case "follow-requests":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   291
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   292
			if opt.acceptFR || opt.rejectFR {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   293
				return errors.New("incompatible options")
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
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   296
			if !opt.acceptFR && !opt.rejectFR { // No flag
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   297
				return errors.New("missing parameter (--list, --accept or --reject)")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   298
			}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   299
			// This is a FR reply
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
			if opt.accountID < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   304
				return errors.New("missing account ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   305
			}
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
	case "relationships":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   308
		if opt.accountID < 1 && len(opt.accountIDs) == 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   309
			return errors.New("missing account IDs")
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 > 0 && len(opt.accountIDs) > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   312
			return errors.New("incompatible options")
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
	case "reports":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   315
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   316
			break // No argument needed
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   317
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   318
		if opt.accountID < 1 || len(opt.statusIDs) == 0 || opt.comment == "" {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   319
			return errors.New("missing parameter")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   320
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   321
	default:
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   322
		// The other subcommands here require an account ID
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   323
		if opt.accountID < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   324
			return errors.New("missing account ID")
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
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   327
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   328
	// All account subcommands need to have signed in
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   329
	if err := madonInit(true); err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   330
		return err
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   331
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   332
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   333
	var obj interface{}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   334
	var err error
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   335
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   336
	switch subcmd {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   337
	case "show":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   338
		var account *madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   339
		if opt.accountID > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   340
			account, err = gClient.GetAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   341
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   342
			account, err = gClient.GetCurrentAccount()
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   343
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   344
		obj = account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   345
	case "search":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   346
		var accountList []madon.Account
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   347
		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), int(opt.limit))
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   348
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   349
	case "followers":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   350
		var accountList []madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   351
		accountList, err = gClient.GetAccountFollowers(opt.accountID)
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   352
		if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   353
			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
   354
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   355
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   356
	case "following":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   357
		var accountList []madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   358
		accountList, err = gClient.GetAccountFollowing(opt.accountID)
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   359
		if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   360
			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
   361
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   362
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   363
	case "statuses":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   364
		var statusList []madon.Status
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   365
		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies)
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   366
		if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   367
			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
   368
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   369
		obj = statusList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   370
	case "follow":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   371
		if opt.unset {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   372
			err = gClient.UnfollowAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   373
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   374
			if opt.accountID > 0 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   375
				err = gClient.FollowAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   376
			} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   377
				var account *madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   378
				account, err = gClient.FollowRemoteAccount(opt.remoteUID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   379
				obj = account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   380
			}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   381
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   382
	case "follow-requests":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   383
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   384
			var followRequests []madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   385
			followRequests, err = gClient.GetAccountFollowRequests()
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   386
			if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   387
				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
   388
			}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   389
			obj = followRequests
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   390
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   391
			err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   392
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   393
	case "block":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   394
		if opt.unset {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   395
			err = gClient.UnblockAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   396
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   397
			err = gClient.BlockAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   398
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   399
	case "mute":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   400
		if opt.unset {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   401
			err = gClient.UnmuteAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   402
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   403
			err = gClient.MuteAccount(opt.accountID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   404
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   405
	case "favourites":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   406
		var statusList []madon.Status
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   407
		statusList, err = gClient.GetFavourites()
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   408
		if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   409
			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
   410
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   411
		obj = statusList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   412
	case "blocks":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   413
		var accountList []madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   414
		accountList, err = gClient.GetBlockedAccounts()
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   415
		if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   416
			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
   417
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   418
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   419
	case "mutes":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   420
		var accountList []madon.Account
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   421
		accountList, err = gClient.GetMutedAccounts()
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   422
		if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   423
			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
   424
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   425
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   426
	case "relationships":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   427
		var ids []int
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   428
		ids, err = splitIDs(opt.accountIDs)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   429
		if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   430
			return errors.New("cannot parse account IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   431
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   432
		if opt.accountID > 0 { // Allow --account-id
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   433
			ids = []int{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
		if len(ids) < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   436
			return errors.New("missing account IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   437
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   438
		var relationships []madon.Relationship
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   439
		relationships, err = gClient.GetAccountRelationships(ids)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   440
		obj = relationships
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   441
	case "reports":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   442
		if opt.list {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   443
			var reports []madon.Report
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   444
			reports, err = gClient.GetReports()
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   445
			if opt.limit > 0 {
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   446
				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
   447
			}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   448
			obj = reports
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   449
			break
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
		// Send a report
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   452
		var ids []int
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   453
		ids, err = splitIDs(opt.statusIDs)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   454
		if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   455
			return errors.New("cannot parse status IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   456
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   457
		if len(ids) < 1 {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   458
			return errors.New("missing status IDs")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   459
		}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   460
		var report *madon.Report
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   461
		report, err = gClient.ReportUser(opt.accountID, ids, opt.comment)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   462
		obj = report
6
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   463
	case "update":
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   464
		var dn, note, avatar, header *string
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   465
		change := false
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   466
		if updateFlags.Lookup("display-name").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   467
			dn = &opt.displayName
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   468
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   469
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   470
		if updateFlags.Lookup("note").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   471
			note = &opt.note
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   472
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   473
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   474
		if updateFlags.Lookup("avatar").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   475
			avatar = &opt.avatar
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   476
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   477
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   478
		if updateFlags.Lookup("header").Changed {
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   479
			header = &opt.header
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   480
			change = true
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   481
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   482
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   483
		if !change { // We want at least one update
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   484
			return errors.New("missing parameters")
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   485
		}
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   486
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   487
		var account *madon.Account
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   488
		account, err = gClient.UpdateAccount(dn, note, avatar, header)
5228e517c455 Add account update
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   489
		obj = account
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   490
	default:
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   491
		return errors.New("accountSubcommand: internal error")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   492
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   493
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   494
	if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   495
		errPrint("Error: %s", err.Error())
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   496
		return nil
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 obj == nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   499
		return nil
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   502
	p, err := getPrinter()
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   503
	if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   504
		return err
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   505
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   506
	return p.PrintObj(obj, nil, "")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   507
}