author | Mikael Berthe <mikael@lilotux.net> |
Tue, 20 Mar 2018 16:47:06 +0100 | |
changeset 197 | 0b0fd2f02296 |
parent 185 | 564d92b54b00 |
child 215 | b0bc0a131b59 |
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 |
0 | 24 |
unset bool |
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 |
statusCmd.MarkPersistentFlagRequired("status-id") |
|
59 |
||
60 |
// Subcommand flags |
|
61 |
statusReblogSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Unreblog the status") |
|
62 |
statusFavouriteSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Remove the status from the favourites") |
|
179 | 63 |
statusPinSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Unpin the status") |
0 | 64 |
statusPostSubcommand.Flags().BoolVar(&statusOpts.sensitive, "sensitive", false, "Mark post as sensitive (NSFW)") |
65 |
statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)") |
|
66 |
statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)") |
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
|
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
75 |
// Flag completion |
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
76 |
annotation := make(map[string][]string) |
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
77 |
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
|
78 |
|
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
79 |
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
|
80 |
|
ce4000ac7294
Add flag to reply with same visibility as original message
Mikael Berthe <mikael@lilotux.net>
parents:
167
diff
changeset
|
81 |
// 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
|
82 |
statusPostFlags = statusPostSubcommand.Flags() |
0 | 83 |
} |
84 |
||
85 |
// statusCmd represents the status command |
|
86 |
// This command does nothing without a subcommand |
|
87 |
var statusCmd = &cobra.Command{ |
|
88 |
Use: "status --status-id ID subcommand", |
|
89 |
Aliases: []string{"st"}, |
|
90 |
Short: "Get status details", |
|
91 |
//Long: `TBW...`, // TODO |
|
92 |
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
|
93 |
// This is common to status and all status subcommands but "post" |
|
94 |
if statusOpts.statusID < 1 && cmd.Name() != "post" { |
|
95 |
return errors.New("missing status ID") |
|
96 |
} |
|
113 | 97 |
return madonInit(true) |
0 | 98 |
}, |
99 |
} |
|
100 |
||
101 |
var statusSubcommands = []*cobra.Command{ |
|
102 |
&cobra.Command{ |
|
103 |
Use: "show", |
|
104 |
Aliases: []string{"display"}, |
|
105 |
Short: "Get the status", |
|
106 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
107 |
return statusSubcommandRunE(cmd.Name(), args) |
|
108 |
}, |
|
109 |
}, |
|
110 |
&cobra.Command{ |
|
111 |
Use: "context", |
|
112 |
Short: "Get the status context", |
|
113 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
114 |
return statusSubcommandRunE(cmd.Name(), args) |
|
115 |
}, |
|
116 |
}, |
|
117 |
&cobra.Command{ |
|
118 |
Use: "card", |
|
119 |
Short: "Get the status card", |
|
120 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
121 |
return statusSubcommandRunE(cmd.Name(), args) |
|
122 |
}, |
|
123 |
}, |
|
124 |
&cobra.Command{ |
|
125 |
Use: "reblogged-by", |
|
126 |
Short: "Display accounts which reblogged the status", |
|
127 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
128 |
return statusSubcommandRunE(cmd.Name(), args) |
|
129 |
}, |
|
130 |
}, |
|
131 |
&cobra.Command{ |
|
132 |
Use: "favourited-by", |
|
133 |
Aliases: []string{"favorited-by"}, |
|
134 |
Short: "Display accounts which favourited the status", |
|
135 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
136 |
return statusSubcommandRunE(cmd.Name(), args) |
|
137 |
}, |
|
138 |
}, |
|
139 |
&cobra.Command{ |
|
140 |
Use: "delete", |
|
141 |
Aliases: []string{"rm"}, |
|
142 |
Short: "Delete the status", |
|
143 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
144 |
return statusSubcommandRunE(cmd.Name(), args) |
|
145 |
}, |
|
146 |
}, |
|
154
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
147 |
&cobra.Command{ |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
148 |
Use: "mute-conversation", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
149 |
Aliases: []string{"mute"}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
150 |
Short: "Mute the conversation containing the status", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
151 |
RunE: func(cmd *cobra.Command, args []string) error { |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
152 |
return statusSubcommandRunE(cmd.Name(), args) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
153 |
}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
154 |
}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
155 |
&cobra.Command{ |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
156 |
Use: "unmute-conversation", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
157 |
Aliases: []string{"unmute"}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
158 |
Short: "Unmute the conversation containing the status", |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
159 |
RunE: func(cmd *cobra.Command, args []string) error { |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
160 |
return statusSubcommandRunE(cmd.Name(), args) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
161 |
}, |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
162 |
}, |
0 | 163 |
statusReblogSubcommand, |
164 |
statusFavouriteSubcommand, |
|
179 | 165 |
statusPinSubcommand, |
0 | 166 |
statusPostSubcommand, |
167 |
} |
|
168 |
||
169 |
var statusReblogSubcommand = &cobra.Command{ |
|
170 |
Use: "boost", |
|
171 |
Aliases: []string{"reblog"}, |
|
172 |
Short: "Boost (reblog) or unreblog the status", |
|
173 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
174 |
return statusSubcommandRunE(cmd.Name(), args) |
|
175 |
}, |
|
176 |
} |
|
177 |
||
178 |
var statusFavouriteSubcommand = &cobra.Command{ |
|
179 |
Use: "favourite", |
|
180 |
Aliases: []string{"favorite", "fave"}, |
|
181 |
Short: "Mark/unmark the status as favourite", |
|
182 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
183 |
return statusSubcommandRunE(cmd.Name(), args) |
|
184 |
}, |
|
185 |
} |
|
186 |
||
179 | 187 |
var statusPinSubcommand = &cobra.Command{ |
188 |
Use: "pin", |
|
189 |
Short: "Pin/unpin the status", |
|
190 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
191 |
return statusSubcommandRunE(cmd.Name(), args) |
|
192 |
}, |
|
193 |
} |
|
194 |
||
0 | 195 |
var statusPostSubcommand = &cobra.Command{ |
196 |
Use: "post", |
|
197 |
Aliases: []string{"toot", "pouet"}, |
|
198 |
Short: "Post a message (same as 'madonctl toot')", |
|
199 |
Example: ` madonctl status post --spoiler Warning "Hello, World" |
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
echo "Hello from #madonctl" | madonctl status toot --stdin |
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
206 |
|
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
207 |
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
|
208 |
'default_visibility' (or with an environmnent variable).`, |
0 | 209 |
RunE: func(cmd *cobra.Command, args []string) error { |
210 |
return statusSubcommandRunE(cmd.Name(), args) |
|
211 |
}, |
|
212 |
} |
|
213 |
||
214 |
func statusSubcommandRunE(subcmd string, args []string) error { |
|
215 |
opt := statusOpts |
|
216 |
||
217 |
var obj interface{} |
|
218 |
var err error |
|
219 |
||
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
220 |
var limOpts *madon.LimitParams |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
221 |
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
|
222 |
limOpts = new(madon.LimitParams) |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
223 |
limOpts.All = opt.all |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
224 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
225 |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
226 |
if opt.limit > 0 { |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
227 |
limOpts.Limit = int(opt.limit) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
228 |
} |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
229 |
/* |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
230 |
if opt.maxID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
231 |
limOpts.MaxID = int64(opt.maxID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
232 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
233 |
if opt.sinceID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
234 |
limOpts.SinceID = int64(opt.sinceID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
235 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
236 |
*/ |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
237 |
|
0 | 238 |
switch subcmd { |
239 |
case "show": |
|
240 |
var status *madon.Status |
|
241 |
status, err = gClient.GetStatus(opt.statusID) |
|
242 |
obj = status |
|
243 |
case "context": |
|
244 |
var context *madon.Context |
|
245 |
context, err = gClient.GetStatusContext(opt.statusID) |
|
246 |
obj = context |
|
247 |
case "card": |
|
248 |
var context *madon.Card |
|
249 |
context, err = gClient.GetStatusCard(opt.statusID) |
|
250 |
obj = context |
|
251 |
case "reblogged-by": |
|
252 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
} |
0 | 257 |
obj = accountList |
258 |
case "favourited-by": |
|
259 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
} |
0 | 264 |
obj = accountList |
265 |
case "delete": |
|
266 |
err = gClient.DeleteStatus(opt.statusID) |
|
267 |
case "boost": |
|
268 |
if opt.unset { |
|
269 |
err = gClient.UnreblogStatus(opt.statusID) |
|
270 |
} else { |
|
271 |
err = gClient.ReblogStatus(opt.statusID) |
|
272 |
} |
|
273 |
case "favourite": |
|
274 |
if opt.unset { |
|
275 |
err = gClient.UnfavouriteStatus(opt.statusID) |
|
276 |
} else { |
|
277 |
err = gClient.FavouriteStatus(opt.statusID) |
|
278 |
} |
|
179 | 279 |
case "pin": |
280 |
if opt.unset { |
|
281 |
err = gClient.UnpinStatus(opt.statusID) |
|
282 |
} else { |
|
283 |
err = gClient.PinStatus(opt.statusID) |
|
284 |
} |
|
154
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
285 |
case "mute-conversation": |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
286 |
var s *madon.Status |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
287 |
s, err = gClient.MuteConversation(opt.statusID) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
288 |
obj = s |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
289 |
case "unmute-conversation": |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
290 |
var s *madon.Status |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
291 |
s, err = gClient.UnmuteConversation(opt.statusID) |
f07a61122b0d
Add status {mute,unmute}-conversation
Mikael Berthe <mikael@lilotux.net>
parents:
129
diff
changeset
|
292 |
obj = s |
0 | 293 |
case "post": // toot |
294 |
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
|
295 |
text := strings.Join(args, " ") |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
296 |
if opt.textFilePath != "" { |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
297 |
var b []byte |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
298 |
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
|
299 |
break |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
300 |
} |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
301 |
text = string(b) |
71
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
302 |
} else if opt.stdin { |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
303 |
var b []byte |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
304 |
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
|
305 |
break |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
306 |
} |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
307 |
text = string(b) |
15
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
308 |
} |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
309 |
s, err = toot(text) |
0 | 310 |
obj = s |
311 |
default: |
|
312 |
return errors.New("statusSubcommand: internal error") |
|
313 |
} |
|
314 |
||
315 |
if err != nil { |
|
316 |
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
|
317 |
os.Exit(1) |
0 | 318 |
} |
319 |
if obj == nil { |
|
320 |
return nil |
|
321 |
} |
|
322 |
||
323 |
p, err := getPrinter() |
|
324 |
if err != nil { |
|
81
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
79
diff
changeset
|
325 |
errPrint("Error: %s", err.Error()) |
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
79
diff
changeset
|
326 |
os.Exit(1) |
0 | 327 |
} |
110 | 328 |
return p.printObj(obj) |
0 | 329 |
} |