author | Mikael Berthe <mikael@lilotux.net> |
Fri, 07 Sep 2018 22:53:59 +0200 | |
changeset 237 | ac5ce4c0e79b |
parent 221 | 970c319e1f7c |
child 239 | 605a00e9d1ab |
permissions | -rw-r--r-- |
185 | 1 |
// Copyright © 2017-2018 Mikael Berthe <mikael@lilotux.net> |
0 | 2 |
// |
3 |
// Licensed under the MIT license. |
|
4 |
// Please see the LICENSE file is this directory. |
|
5 |
||
6 |
package cmd |
|
7 |
||
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 | 11 |
"strings" |
12 |
||
45
b58a7ea1aeb2
Use github.com/pkg/errors
Mikael Berthe <mikael@lilotux.net>
parents:
44
diff
changeset
|
13 |
"github.com/pkg/errors" |
0 | 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 | 16 |
|
17 |
"github.com/McKael/madon" |
|
18 |
) |
|
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 | 22 |
var statusOpts struct { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
23 |
statusID int64 |
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 | 25 |
|
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 |
ce4000ac7294
Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents:
167
diff
changeset
|
30 |
inReplyToID int64 |
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 | 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 |
0 | 42 |
} |
43 |
||
44 |
func init() { |
|
45 |
RootCmd.AddCommand(statusCmd) |
|
46 |
||
47 |
// Subcommands |
|
48 |
statusCmd.AddCommand(statusSubcommands...) |
|
49 |
||
50 |
// Global flags |
|
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
51 |
statusCmd.PersistentFlags().Int64VarP(&statusOpts.statusID, "status-id", "s", 0, "Status ID number") |
167
1341bacd01c9
Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents:
154
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
//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
|
55 |
//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
|
56 |
statusCmd.PersistentFlags().BoolVar(&statusOpts.all, "all", false, "Fetch all results (for reblogged-by/favourited-by)") |
0 | 57 |
|
58 |
// Subcommand flags |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
statusPinSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Unpin the status (deprecated)") |
0 | 62 |
statusPostSubcommand.Flags().BoolVar(&statusOpts.sensitive, "sensitive", false, "Mark post as sensitive (NSFW)") |
63 |
statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)") |
|
64 |
statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)") |
|
65 |
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
|
66 |
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
|
67 |
statusPostSubcommand.Flags().StringVar(&statusOpts.textFilePath, "text-file", "", "Text file name (message content)") |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
68 |
statusPostSubcommand.Flags().Int64VarP(&statusOpts.inReplyToID, "in-reply-to", "r", 0, "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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
73 |
// Deprecated flags |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
|
35
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
78 |
// Flag completion |
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
79 |
annotation := make(map[string][]string) |
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
80 |
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
|
81 |
|
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
82 |
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
|
83 |
|
ce4000ac7294
Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents:
167
diff
changeset
|
84 |
// 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
|
85 |
statusPostFlags = statusPostSubcommand.Flags() |
0 | 86 |
} |
87 |
||
88 |
// statusCmd represents the status command |
|
89 |
// This command does nothing without a subcommand |
|
90 |
var statusCmd = &cobra.Command{ |
|
91 |
Use: "status --status-id ID subcommand", |
|
92 |
Aliases: []string{"st"}, |
|
93 |
Short: "Get status details", |
|
94 |
//Long: `TBW...`, // TODO |
|
95 |
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
|
96 |
// This is common to status and all status subcommands but "post" |
|
97 |
if statusOpts.statusID < 1 && cmd.Name() != "post" { |
|
98 |
return errors.New("missing status ID") |
|
99 |
} |
|
113 | 100 |
return madonInit(true) |
0 | 101 |
}, |
102 |
} |
|
103 |
||
104 |
var statusSubcommands = []*cobra.Command{ |
|
105 |
&cobra.Command{ |
|
106 |
Use: "show", |
|
107 |
Aliases: []string{"display"}, |
|
108 |
Short: "Get the status", |
|
109 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
110 |
return statusSubcommandRunE(cmd.Name(), args) |
|
111 |
}, |
|
112 |
}, |
|
113 |
&cobra.Command{ |
|
114 |
Use: "context", |
|
115 |
Short: "Get the status context", |
|
116 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
117 |
return statusSubcommandRunE(cmd.Name(), args) |
|
118 |
}, |
|
119 |
}, |
|
120 |
&cobra.Command{ |
|
121 |
Use: "card", |
|
122 |
Short: "Get the status card", |
|
123 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
124 |
return statusSubcommandRunE(cmd.Name(), args) |
|
125 |
}, |
|
126 |
}, |
|
127 |
&cobra.Command{ |
|
128 |
Use: "reblogged-by", |
|
129 |
Short: "Display accounts which reblogged the status", |
|
130 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
131 |
return statusSubcommandRunE(cmd.Name(), args) |
|
132 |
}, |
|
133 |
}, |
|
134 |
&cobra.Command{ |
|
135 |
Use: "favourited-by", |
|
136 |
Aliases: []string{"favorited-by"}, |
|
137 |
Short: "Display accounts which favourited the status", |
|
138 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
139 |
return statusSubcommandRunE(cmd.Name(), args) |
|
140 |
}, |
|
141 |
}, |
|
142 |
&cobra.Command{ |
|
143 |
Use: "delete", |
|
144 |
Aliases: []string{"rm"}, |
|
145 |
Short: "Delete the status", |
|
146 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
147 |
return statusSubcommandRunE(cmd.Name(), args) |
|
148 |
}, |
|
149 |
}, |
|
154
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
150 |
&cobra.Command{ |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
151 |
Use: "mute-conversation", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
152 |
Aliases: []string{"mute"}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
153 |
Short: "Mute the conversation containing the status", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
154 |
RunE: func(cmd *cobra.Command, args []string) error { |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
155 |
return statusSubcommandRunE(cmd.Name(), args) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
156 |
}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
157 |
}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
158 |
&cobra.Command{ |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
159 |
Use: "unmute-conversation", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
160 |
Aliases: []string{"unmute"}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
161 |
Short: "Unmute the conversation containing the status", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
162 |
RunE: func(cmd *cobra.Command, args []string) error { |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
163 |
return statusSubcommandRunE(cmd.Name(), args) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
164 |
}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
165 |
}, |
0 | 166 |
statusReblogSubcommand, |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
167 |
statusUnreblogSubcommand, |
0 | 168 |
statusFavouriteSubcommand, |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
169 |
statusUnfavouriteSubcommand, |
179 | 170 |
statusPinSubcommand, |
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
171 |
statusUnpinSubcommand, |
0 | 172 |
statusPostSubcommand, |
173 |
} |
|
174 |
||
175 |
var statusReblogSubcommand = &cobra.Command{ |
|
176 |
Use: "boost", |
|
177 |
Aliases: []string{"reblog"}, |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
178 |
Short: "Boost (reblog) a status message", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
179 |
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
|
180 |
return statusSubcommandRunE(cmd.Name(), args) |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
181 |
}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
182 |
} |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
183 |
|
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
184 |
var statusUnreblogSubcommand = &cobra.Command{ |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
185 |
Use: "unboost", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
186 |
Aliases: []string{"unreblog"}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
187 |
Short: "Cancel boost (reblog) of a status message", |
0 | 188 |
RunE: func(cmd *cobra.Command, args []string) error { |
189 |
return statusSubcommandRunE(cmd.Name(), args) |
|
190 |
}, |
|
191 |
} |
|
192 |
||
193 |
var statusFavouriteSubcommand = &cobra.Command{ |
|
194 |
Use: "favourite", |
|
195 |
Aliases: []string{"favorite", "fave"}, |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
196 |
Short: "Mark the status as favourite", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
197 |
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
|
198 |
return statusSubcommandRunE(cmd.Name(), args) |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
199 |
}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
200 |
} |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
201 |
|
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
202 |
var statusUnfavouriteSubcommand = &cobra.Command{ |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
203 |
Use: "unfavourite", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
204 |
Aliases: []string{"unfavorite", "unfave"}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
205 |
Short: "Unmark the status as favourite", |
0 | 206 |
RunE: func(cmd *cobra.Command, args []string) error { |
207 |
return statusSubcommandRunE(cmd.Name(), args) |
|
208 |
}, |
|
209 |
} |
|
210 |
||
179 | 211 |
var statusPinSubcommand = &cobra.Command{ |
212 |
Use: "pin", |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
213 |
Short: "Pin a status", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
214 |
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
|
215 |
return statusSubcommandRunE(cmd.Name(), args) |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
216 |
}, |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
217 |
} |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
218 |
|
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
219 |
var statusUnpinSubcommand = &cobra.Command{ |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
220 |
Use: "unpin", |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
221 |
Short: "Unpin a status", |
179 | 222 |
RunE: func(cmd *cobra.Command, args []string) error { |
223 |
return statusSubcommandRunE(cmd.Name(), args) |
|
224 |
}, |
|
225 |
} |
|
226 |
||
0 | 227 |
var statusPostSubcommand = &cobra.Command{ |
228 |
Use: "post", |
|
229 |
Aliases: []string{"toot", "pouet"}, |
|
230 |
Short: "Post a message (same as 'madonctl toot')", |
|
221
970c319e1f7c
Update toot online examples
Mikael Berthe <mikael@lilotux.net>
parents:
215
diff
changeset
|
231 |
Example: ` madonctl status post "Hello, World" |
970c319e1f7c
Update toot online examples
Mikael Berthe <mikael@lilotux.net>
parents:
215
diff
changeset
|
232 |
madonctl status post --spoiler Warning "Spoiled" |
970c319e1f7c
Update toot online examples
Mikael Berthe <mikael@lilotux.net>
parents:
215
diff
changeset
|
233 |
madonctl status toot --visibility private "To my followers only" |
0 | 234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
echo "Hello from #madonctl" | madonctl status toot --stdin |
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
240 |
|
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
241 |
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
|
242 |
'default_visibility' (or with an environmnent variable).`, |
0 | 243 |
RunE: func(cmd *cobra.Command, args []string) error { |
244 |
return statusSubcommandRunE(cmd.Name(), args) |
|
245 |
}, |
|
246 |
} |
|
247 |
||
248 |
func statusSubcommandRunE(subcmd string, args []string) error { |
|
249 |
opt := statusOpts |
|
250 |
||
251 |
var obj interface{} |
|
252 |
var err error |
|
253 |
||
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
254 |
var limOpts *madon.LimitParams |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
255 |
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
|
256 |
limOpts = new(madon.LimitParams) |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
257 |
limOpts.All = opt.all |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
258 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
259 |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
260 |
if opt.limit > 0 { |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
261 |
limOpts.Limit = int(opt.limit) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
262 |
} |
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 |
if opt.maxID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
265 |
limOpts.MaxID = int64(opt.maxID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
266 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
267 |
if opt.sinceID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
268 |
limOpts.SinceID = int64(opt.sinceID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
269 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
270 |
*/ |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
271 |
|
0 | 272 |
switch subcmd { |
273 |
case "show": |
|
274 |
var status *madon.Status |
|
275 |
status, err = gClient.GetStatus(opt.statusID) |
|
276 |
obj = status |
|
277 |
case "context": |
|
278 |
var context *madon.Context |
|
279 |
context, err = gClient.GetStatusContext(opt.statusID) |
|
280 |
obj = context |
|
281 |
case "card": |
|
282 |
var context *madon.Card |
|
283 |
context, err = gClient.GetStatusCard(opt.statusID) |
|
284 |
obj = context |
|
285 |
case "reblogged-by": |
|
286 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
} |
0 | 291 |
obj = accountList |
292 |
case "favourited-by": |
|
293 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
} |
0 | 298 |
obj = accountList |
299 |
case "delete": |
|
300 |
err = gClient.DeleteStatus(opt.statusID) |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
301 |
case "boost", "unboost": |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
302 |
if opt.unset || subcmd == "unboost" { |
0 | 303 |
err = gClient.UnreblogStatus(opt.statusID) |
304 |
} else { |
|
305 |
err = gClient.ReblogStatus(opt.statusID) |
|
306 |
} |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
307 |
case "favourite", "unfavourite": |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
308 |
if opt.unset || subcmd == "unfavourite" { |
0 | 309 |
err = gClient.UnfavouriteStatus(opt.statusID) |
310 |
} else { |
|
311 |
err = gClient.FavouriteStatus(opt.statusID) |
|
312 |
} |
|
237
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
313 |
case "pin", "unpin": |
ac5ce4c0e79b
Deprecate flag '--unset' and introduce subcommand (unpin, unboost...)
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
314 |
if opt.unset || subcmd == "unpin" { |
179 | 315 |
err = gClient.UnpinStatus(opt.statusID) |
316 |
} else { |
|
317 |
err = gClient.PinStatus(opt.statusID) |
|
318 |
} |
|
154
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
319 |
case "mute-conversation": |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
320 |
var s *madon.Status |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
321 |
s, err = gClient.MuteConversation(opt.statusID) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
322 |
obj = s |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
323 |
case "unmute-conversation": |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
324 |
var s *madon.Status |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
325 |
s, err = gClient.UnmuteConversation(opt.statusID) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
326 |
obj = s |
0 | 327 |
case "post": // toot |
328 |
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
|
329 |
text := strings.Join(args, " ") |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
330 |
if opt.textFilePath != "" { |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
331 |
var b []byte |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
332 |
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
|
333 |
break |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
334 |
} |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
335 |
text = string(b) |
71
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
336 |
} else if opt.stdin { |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
337 |
var b []byte |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
338 |
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
|
339 |
break |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
340 |
} |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
341 |
text = string(b) |
15
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
342 |
} |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
343 |
s, err = toot(text) |
0 | 344 |
obj = s |
345 |
default: |
|
346 |
return errors.New("statusSubcommand: internal error") |
|
347 |
} |
|
348 |
||
349 |
if err != nil { |
|
350 |
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
|
351 |
os.Exit(1) |
0 | 352 |
} |
353 |
if obj == nil { |
|
354 |
return nil |
|
355 |
} |
|
356 |
||
357 |
p, err := getPrinter() |
|
358 |
if err != nil { |
|
81
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
79
diff
changeset
|
359 |
errPrint("Error: %s", err.Error()) |
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
79
diff
changeset
|
360 |
os.Exit(1) |
0 | 361 |
} |
110 | 362 |
return p.printObj(obj) |
0 | 363 |
} |