cmd/status.go
author rjp <zimpenfish@gmail.com>
Mon, 23 Jan 2023 16:39:02 +0000
changeset 267 5b91a65ba95a
parent 239 605a00e9d1ab
child 268 4dd196a4ee7c
permissions -rw-r--r--
Update to handle non-int64 IDs Pleroma/Akkoma and GotoSocial use opaque IDs rather than `int64`s like Mastodon which means that `madon` can't talk to either of those. This commit updates everything that can be an ID to `madon.ActivityID` which is an alias for `string` - can't create a specific type for it since there's more than a few places where they're concatenated directly to strings for URLs, etc. Which means it could just as easily be a direct `string` type itself but I find that having distinct types can often make the code more readable and understandable. One extra bit is that `statusOpts` has grown a `_hasReplyTo` boolean to indicate whether the `--in-reply-to` flag was given or not because we can't distinguish because "empty because default" or "empty because given and empty". Another way around this would be to set the default to some theoretically impossible or unlikely string but you never know when someone might spin up an instance where, e.g., admin posts have negative integer IDs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
185
564d92b54b00 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 179
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 (
15
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
     9
	"io/ioutil"
47
82d8b6074309 Set exit code to non-zero when API calls fail
Mikael Berthe <mikael@lilotux.net>
parents: 45
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
45
b58a7ea1aeb2 Use github.com/pkg/errors
Mikael Berthe <mikael@lilotux.net>
parents: 44
diff changeset
    13
	"github.com/pkg/errors"
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
	"github.com/spf13/cobra"
176
7efbbed5cf3c Fix duplicate usage of updateFlags variable name
Mikael Berthe <mikael@lilotux.net>
parents: 168
diff changeset
    15
	flag "github.com/spf13/pflag"
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
239
605a00e9d1ab Switch to Go modules (and bump Go version requirement)
Mikael Berthe <mikael@lilotux.net>
parents: 237
diff changeset
    17
	"github.com/McKael/madon/v2"
0
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
176
7efbbed5cf3c Fix duplicate usage of updateFlags variable name
Mikael Berthe <mikael@lilotux.net>
parents: 168
diff changeset
    20
var statusPostFlags *flag.FlagSet
7efbbed5cf3c Fix duplicate usage of updateFlags variable name
Mikael Berthe <mikael@lilotux.net>
parents: 168
diff changeset
    21
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
var statusOpts struct {
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    23
	statusID madon.ActivityID
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    24
	unset    bool // TODO remove eventually?
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
	// The following fields are used for the post/toot command
168
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    27
	visibility     string
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    28
	sensitive      bool
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    29
	spoiler        string
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    30
	inReplyToID    madon.ActivityID
168
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    31
	mediaIDs       string
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    32
	mediaFilePath  string
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    33
	textFilePath   string
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    34
	stdin          bool
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    35
	addMentions    bool
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    36
	sameVisibility bool
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    38
	// Used for several subcommands to limit the number of results
167
1341bacd01c9 Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents: 154
diff changeset
    39
	limit, keep uint
44
6da40ca4534c Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents: 35
diff changeset
    40
	//sinceID, maxID int64
30
14561d44211b Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
    41
	all bool
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    42
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    43
	// Used to indicate whether `in-reply-to` flag is present or not.
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    44
	_hasReplyTo bool
0
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    47
func init() {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    48
	RootCmd.AddCommand(statusCmd)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    49
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
	// Subcommands
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
	statusCmd.AddCommand(statusSubcommands...)
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
	// Global flags
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    54
	statusCmd.PersistentFlags().StringVarP(&statusOpts.statusID, "status-id", "s", "", "Status ID number")
167
1341bacd01c9 Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents: 154
diff changeset
    55
	statusCmd.PersistentFlags().UintVarP(&statusOpts.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: 154
diff changeset
    56
	statusCmd.PersistentFlags().UintVarP(&statusOpts.keep, "keep", "k", 0, "Limit number of results")
44
6da40ca4534c Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents: 35
diff changeset
    57
	//statusCmd.PersistentFlags().Int64Var(&statusOpts.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: 35
diff changeset
    58
	//statusCmd.PersistentFlags().Int64Var(&statusOpts.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: 22
diff changeset
    59
	statusCmd.PersistentFlags().BoolVar(&statusOpts.all, "all", false, "Fetch all results (for reblogged-by/favourited-by)")
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
	// Subcommand flags
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    62
	statusReblogSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Unreblog the status (deprecated)")
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    63
	statusFavouriteSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Remove the status from the favourites (deprecated)")
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    64
	statusPinSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Unpin the status (deprecated)")
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    65
	statusPostSubcommand.Flags().BoolVar(&statusOpts.sensitive, "sensitive", false, "Mark post as sensitive (NSFW)")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    66
	statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    67
	statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    68
	statusPostSubcommand.Flags().StringVar(&statusOpts.mediaIDs, "media-ids", "", "Comma-separated list of media IDs")
15
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    69
	statusPostSubcommand.Flags().StringVarP(&statusOpts.mediaFilePath, "file", "f", "", "Media file name")
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    70
	statusPostSubcommand.Flags().StringVar(&statusOpts.textFilePath, "text-file", "", "Text file name (message content)")
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
    71
	statusPostSubcommand.Flags().StringVarP(&statusOpts.inReplyToID, "in-reply-to", "r", "", "Status ID to reply to")
71
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
    72
	statusPostSubcommand.Flags().BoolVar(&statusOpts.stdin, "stdin", false, "Read message content from standard input")
129
11966471aac3 toot: Add flag --add-mentions to add mentions when replying
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
    73
	statusPostSubcommand.Flags().BoolVar(&statusOpts.addMentions, "add-mentions", false, "Add mentions when replying")
168
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    74
	statusPostSubcommand.Flags().BoolVar(&statusOpts.sameVisibility, "same-visibility", false, "Use same visibility as original message (for replies)")
35
61ed03c3f134 Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents: 30
diff changeset
    75
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    76
	// Deprecated flags
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    77
	statusReblogSubcommand.Flags().MarkDeprecated("unset", "please use unboost instead")
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    78
	statusFavouriteSubcommand.Flags().MarkDeprecated("unset", "please use unfavourite instead")
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    79
	statusPinSubcommand.Flags().MarkDeprecated("unset", "please use unpin instead")
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
    80
35
61ed03c3f134 Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents: 30
diff changeset
    81
	// Flag completion
61ed03c3f134 Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents: 30
diff changeset
    82
	annotation := make(map[string][]string)
61ed03c3f134 Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents: 30
diff changeset
    83
	annotation[cobra.BashCompCustom] = []string{"__madonctl_visibility"}
61ed03c3f134 Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents: 30
diff changeset
    84
61ed03c3f134 Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents: 30
diff changeset
    85
	statusPostSubcommand.Flags().Lookup("visibility").Annotations = annotation
168
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    86
ce4000ac7294 Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents: 167
diff changeset
    87
	// This one will be used to check if the options were explicitly set or not
176
7efbbed5cf3c Fix duplicate usage of updateFlags variable name
Mikael Berthe <mikael@lilotux.net>
parents: 168
diff changeset
    88
	statusPostFlags = statusPostSubcommand.Flags()
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    89
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    90
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    91
// statusCmd represents the status command
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    92
// This command does nothing without a subcommand
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    93
var statusCmd = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    94
	Use:     "status --status-id ID subcommand",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    95
	Aliases: []string{"st"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    96
	Short:   "Get status details",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    97
	//Long:    `TBW...`, // TODO
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    98
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    99
		// This is common to status and all status subcommands but "post"
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
   100
		if statusOpts.statusID == "" && cmd.Name() != "post" {
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   101
			return errors.New("missing status ID")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   102
		}
113
2e411da68fd3 Add oauth2 command
Mikael Berthe <mikael@lilotux.net>
parents: 110
diff changeset
   103
		return madonInit(true)
0
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   107
var statusSubcommands = []*cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   108
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   109
		Use:     "show",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   110
		Aliases: []string{"display"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   111
		Short:   "Get the status",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   112
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   113
			return statusSubcommandRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   114
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   115
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   116
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   117
		Use:   "context",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   118
		Short: "Get the status context",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   119
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   120
			return statusSubcommandRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   121
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   122
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   123
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   124
		Use:   "card",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   125
		Short: "Get the status card",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   126
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   127
			return statusSubcommandRunE(cmd.Name(), args)
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
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   130
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   131
		Use:   "reblogged-by",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   132
		Short: "Display accounts which reblogged the status",
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 statusSubcommandRunE(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:     "favourited-by",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   139
		Aliases: []string{"favorited-by"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   140
		Short:   "Display accounts which favourited the status",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   141
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   142
			return statusSubcommandRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   143
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   144
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   145
	&cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   146
		Use:     "delete",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   147
		Aliases: []string{"rm"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   148
		Short:   "Delete the status",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   149
		RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   150
			return statusSubcommandRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   151
		},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   152
	},
154
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   153
	&cobra.Command{
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   154
		Use:     "mute-conversation",
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   155
		Aliases: []string{"mute"},
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   156
		Short:   "Mute the conversation containing the status",
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   157
		RunE: func(cmd *cobra.Command, args []string) error {
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   158
			return statusSubcommandRunE(cmd.Name(), args)
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   159
		},
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   160
	},
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   161
	&cobra.Command{
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   162
		Use:     "unmute-conversation",
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   163
		Aliases: []string{"unmute"},
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   164
		Short:   "Unmute the conversation containing the status",
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   165
		RunE: func(cmd *cobra.Command, args []string) error {
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   166
			return statusSubcommandRunE(cmd.Name(), args)
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   167
		},
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   168
	},
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   169
	statusReblogSubcommand,
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   170
	statusUnreblogSubcommand,
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   171
	statusFavouriteSubcommand,
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   172
	statusUnfavouriteSubcommand,
179
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   173
	statusPinSubcommand,
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   174
	statusUnpinSubcommand,
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   175
	statusPostSubcommand,
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   178
var statusReblogSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   179
	Use:     "boost",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   180
	Aliases: []string{"reblog"},
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   181
	Short:   "Boost (reblog) a status message",
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   182
	RunE: func(cmd *cobra.Command, args []string) error {
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   183
		return statusSubcommandRunE(cmd.Name(), args)
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   184
	},
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   185
}
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   186
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   187
var statusUnreblogSubcommand = &cobra.Command{
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   188
	Use:     "unboost",
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   189
	Aliases: []string{"unreblog"},
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   190
	Short:   "Cancel boost (reblog) of a status message",
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   191
	RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   192
		return statusSubcommandRunE(cmd.Name(), args)
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
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   196
var statusFavouriteSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   197
	Use:     "favourite",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   198
	Aliases: []string{"favorite", "fave"},
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   199
	Short:   "Mark the status as favourite",
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   200
	RunE: func(cmd *cobra.Command, args []string) error {
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   201
		return statusSubcommandRunE(cmd.Name(), args)
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   202
	},
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   203
}
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   204
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   205
var statusUnfavouriteSubcommand = &cobra.Command{
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   206
	Use:     "unfavourite",
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   207
	Aliases: []string{"unfavorite", "unfave"},
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   208
	Short:   "Unmark the status as favourite",
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   209
	RunE: func(cmd *cobra.Command, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   210
		return statusSubcommandRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   211
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   212
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   213
179
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   214
var statusPinSubcommand = &cobra.Command{
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   215
	Use:   "pin",
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   216
	Short: "Pin a status",
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   217
	RunE: func(cmd *cobra.Command, args []string) error {
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   218
		return statusSubcommandRunE(cmd.Name(), args)
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   219
	},
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   220
}
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   221
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   222
var statusUnpinSubcommand = &cobra.Command{
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   223
	Use:   "unpin",
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   224
	Short: "Unpin a status",
179
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   225
	RunE: func(cmd *cobra.Command, args []string) error {
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   226
		return statusSubcommandRunE(cmd.Name(), args)
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   227
	},
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   228
}
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   229
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   230
var statusPostSubcommand = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   231
	Use:     "post",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   232
	Aliases: []string{"toot", "pouet"},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   233
	Short:   "Post a message (same as 'madonctl toot')",
221
970c319e1f7c Update toot online examples
Mikael Berthe <mikael@lilotux.net>
parents: 215
diff changeset
   234
	Example: `  madonctl status post "Hello, World"
970c319e1f7c Update toot online examples
Mikael Berthe <mikael@lilotux.net>
parents: 215
diff changeset
   235
  madonctl status post --spoiler Warning "Spoiled"
970c319e1f7c Update toot online examples
Mikael Berthe <mikael@lilotux.net>
parents: 215
diff changeset
   236
  madonctl status toot --visibility private "To my followers only"
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   237
  madonctl status toot --sensitive --file image.jpg Image
15
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   238
  madonctl status post --media-ids ID1,ID2,ID3 Image
71
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   239
  madonctl status toot --text-file message.txt
129
11966471aac3 toot: Add flag --add-mentions to add mentions when replying
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
   240
  madonctl status post --in-reply-to STATUSID "@user response"
11966471aac3 toot: Add flag --add-mentions to add mentions when replying
Mikael Berthe <mikael@lilotux.net>
parents: 113
diff changeset
   241
  madonctl status post --in-reply-to STATUSID --add-mentions "response"
79
bca27c55be9f Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents: 71
diff changeset
   242
  echo "Hello from #madonctl" | madonctl status toot --stdin
bca27c55be9f Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents: 71
diff changeset
   243
bca27c55be9f Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents: 71
diff changeset
   244
The default visibility can be set in the configuration file with the option
bca27c55be9f Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents: 71
diff changeset
   245
'default_visibility' (or with an environmnent variable).`,
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   246
	RunE: func(cmd *cobra.Command, args []string) error {
267
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
   247
		// Update the extra flag to reflect if `in-reply-to` was present or not
5b91a65ba95a Update to handle non-int64 IDs
rjp <zimpenfish@gmail.com>
parents: 239
diff changeset
   248
		statusOpts._hasReplyTo = cmd.Flags().Lookup("in-reply-to").Changed
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   249
		return statusSubcommandRunE(cmd.Name(), args)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   250
	},
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   251
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   252
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   253
func statusSubcommandRunE(subcmd string, args []string) error {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   254
	opt := statusOpts
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   255
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   256
	var obj interface{}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   257
	var err error
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   258
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   259
	var limOpts *madon.LimitParams
30
14561d44211b Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   260
	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
   261
		limOpts = new(madon.LimitParams)
30
14561d44211b Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   262
		limOpts.All = opt.all
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   263
	}
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   264
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   265
	if opt.limit > 0 {
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   266
		limOpts.Limit = int(opt.limit)
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   267
	}
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   268
	/*
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   269
		if opt.maxID > 0 {
44
6da40ca4534c Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents: 35
diff changeset
   270
			limOpts.MaxID = int64(opt.maxID)
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   271
		}
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   272
		if opt.sinceID > 0 {
44
6da40ca4534c Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents: 35
diff changeset
   273
			limOpts.SinceID = int64(opt.sinceID)
22
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   274
		}
5778b09bc6fe Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents: 20
diff changeset
   275
	*/
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   276
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   277
	switch subcmd {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   278
	case "show":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   279
		var status *madon.Status
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   280
		status, err = gClient.GetStatus(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   281
		obj = status
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   282
	case "context":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   283
		var context *madon.Context
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   284
		context, err = gClient.GetStatusContext(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   285
		obj = context
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   286
	case "card":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   287
		var context *madon.Card
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   288
		context, err = gClient.GetStatusCard(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   289
		obj = context
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   290
	case "reblogged-by":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   291
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   292
		accountList, err = gClient.GetStatusRebloggedBy(opt.statusID, limOpts)
167
1341bacd01c9 Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents: 154
diff changeset
   293
		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: 154
diff changeset
   294
			accountList = accountList[:opt.keep]
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   295
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   296
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   297
	case "favourited-by":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   298
		var accountList []madon.Account
20
b0ccc09f07a2 Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   299
		accountList, err = gClient.GetStatusFavouritedBy(opt.statusID, limOpts)
167
1341bacd01c9 Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents: 154
diff changeset
   300
		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: 154
diff changeset
   301
			accountList = accountList[:opt.keep]
13
f862af8faf17 Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
   302
		}
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   303
		obj = accountList
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   304
	case "delete":
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   305
		err = gClient.DeleteStatus(opt.statusID)
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   306
	case "boost", "unboost":
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   307
		if opt.unset || subcmd == "unboost" {
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   308
			err = gClient.UnreblogStatus(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   309
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   310
			err = gClient.ReblogStatus(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   311
		}
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   312
	case "favourite", "unfavourite":
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   313
		if opt.unset || subcmd == "unfavourite" {
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   314
			err = gClient.UnfavouriteStatus(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   315
		} else {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   316
			err = gClient.FavouriteStatus(opt.statusID)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   317
		}
237
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   318
	case "pin", "unpin":
ac5ce4c0e79b Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents: 221
diff changeset
   319
		if opt.unset || subcmd == "unpin" {
179
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   320
			err = gClient.UnpinStatus(opt.statusID)
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   321
		} else {
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   322
			err = gClient.PinStatus(opt.statusID)
a60295c41321 Pin/Unpin support
Mikael Berthe <mikael@lilotux.net>
parents: 176
diff changeset
   323
		}
154
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   324
	case "mute-conversation":
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   325
		var s *madon.Status
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   326
		s, err = gClient.MuteConversation(opt.statusID)
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   327
		obj = s
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   328
	case "unmute-conversation":
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   329
		var s *madon.Status
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   330
		s, err = gClient.UnmuteConversation(opt.statusID)
f07a61122b0d Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents: 129
diff changeset
   331
		obj = s
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   332
	case "post": // toot
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   333
		var s *madon.Status
15
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   334
		text := strings.Join(args, " ")
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   335
		if opt.textFilePath != "" {
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   336
			var b []byte
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   337
			if b, err = ioutil.ReadFile(opt.textFilePath); err != nil {
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   338
				break
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   339
			}
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   340
			text = string(b)
71
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   341
		} else if opt.stdin {
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   342
			var b []byte
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   343
			if b, err = ioutil.ReadAll(os.Stdin); err != nil {
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   344
				break
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   345
			}
67e3234c26a9 Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
   346
			text = string(b)
15
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   347
		}
8ac069eaa817 Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   348
		s, err = toot(text)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   349
		obj = s
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   350
	default:
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   351
		return errors.New("statusSubcommand: internal error")
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   352
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   353
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   354
	if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   355
		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
   356
		os.Exit(1)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   357
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   358
	if obj == nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   359
		return nil
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   360
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   361
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   362
	p, err := getPrinter()
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   363
	if err != nil {
81
b1671f83e91b Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents: 79
diff changeset
   364
		errPrint("Error: %s", err.Error())
b1671f83e91b Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents: 79
diff changeset
   365
		os.Exit(1)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   366
	}
110
57843255fd1a Refactor printers
Mikael Berthe <mikael@lilotux.net>
parents: 81
diff changeset
   367
	return p.printObj(obj)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   368
}