author | Mikael Berthe <mikael@lilotux.net> |
Sun, 07 May 2017 16:43:51 +0200 | |
changeset 87 | cd1c3f1610e4 |
parent 81 | b1671f83e91b |
child 110 | 57843255fd1a |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
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" |
15 |
||
16 |
"github.com/McKael/madon" |
|
17 |
) |
|
18 |
||
19 |
var statusOpts struct { |
|
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
20 |
statusID int64 |
0 | 21 |
unset bool |
22 |
||
23 |
// The following fields are used for the post/toot command |
|
15
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
24 |
visibility string |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
25 |
sensitive bool |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
26 |
spoiler string |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
27 |
inReplyToID int64 |
15
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
28 |
mediaIDs string |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
29 |
mediaFilePath string |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
30 |
textFilePath string |
71
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
31 |
stdin bool |
0 | 32 |
|
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
33 |
// Used for several subcommands to limit the number of results |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
34 |
limit uint |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
35 |
//sinceID, maxID int64 |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
36 |
all bool |
0 | 37 |
} |
38 |
||
39 |
func init() { |
|
40 |
RootCmd.AddCommand(statusCmd) |
|
41 |
||
42 |
// Subcommands |
|
43 |
statusCmd.AddCommand(statusSubcommands...) |
|
44 |
||
45 |
// Global flags |
|
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
46 |
statusCmd.PersistentFlags().Int64VarP(&statusOpts.statusID, "status-id", "s", 0, "Status ID number") |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
47 |
statusCmd.PersistentFlags().UintVarP(&statusOpts.limit, "limit", "l", 0, "Limit number of results") |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
48 |
//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
|
49 |
//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
|
50 |
statusCmd.PersistentFlags().BoolVar(&statusOpts.all, "all", false, "Fetch all results (for reblogged-by/favourited-by)") |
0 | 51 |
|
52 |
statusCmd.MarkPersistentFlagRequired("status-id") |
|
53 |
||
54 |
// Subcommand flags |
|
55 |
statusReblogSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Unreblog the status") |
|
56 |
statusFavouriteSubcommand.Flags().BoolVar(&statusOpts.unset, "unset", false, "Remove the status from the favourites") |
|
57 |
statusPostSubcommand.Flags().BoolVar(&statusOpts.sensitive, "sensitive", false, "Mark post as sensitive (NSFW)") |
|
58 |
statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)") |
|
59 |
statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)") |
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
statusPostSubcommand.Flags().BoolVar(&statusOpts.stdin, "stdin", false, "Read message content from standard input") |
35
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
65 |
|
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
66 |
// Flag completion |
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
67 |
annotation := make(map[string][]string) |
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
68 |
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
|
69 |
|
61ed03c3f134
Add flag shell completion (values for --output and --visibility)
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
70 |
statusPostSubcommand.Flags().Lookup("visibility").Annotations = annotation |
0 | 71 |
} |
72 |
||
73 |
// statusCmd represents the status command |
|
74 |
// This command does nothing without a subcommand |
|
75 |
var statusCmd = &cobra.Command{ |
|
76 |
Use: "status --status-id ID subcommand", |
|
77 |
Aliases: []string{"st"}, |
|
78 |
Short: "Get status details", |
|
79 |
//Long: `TBW...`, // TODO |
|
80 |
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
|
81 |
// This is common to status and all status subcommands but "post" |
|
82 |
if statusOpts.statusID < 1 && cmd.Name() != "post" { |
|
83 |
return errors.New("missing status ID") |
|
84 |
} |
|
85 |
if err := madonInit(true); err != nil { |
|
86 |
return err |
|
87 |
} |
|
88 |
return nil |
|
89 |
}, |
|
90 |
} |
|
91 |
||
92 |
var statusSubcommands = []*cobra.Command{ |
|
93 |
&cobra.Command{ |
|
94 |
Use: "show", |
|
95 |
Aliases: []string{"display"}, |
|
96 |
Short: "Get the status", |
|
97 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
98 |
return statusSubcommandRunE(cmd.Name(), args) |
|
99 |
}, |
|
100 |
}, |
|
101 |
&cobra.Command{ |
|
102 |
Use: "context", |
|
103 |
Short: "Get the status context", |
|
104 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
105 |
return statusSubcommandRunE(cmd.Name(), args) |
|
106 |
}, |
|
107 |
}, |
|
108 |
&cobra.Command{ |
|
109 |
Use: "card", |
|
110 |
Short: "Get the status card", |
|
111 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
112 |
return statusSubcommandRunE(cmd.Name(), args) |
|
113 |
}, |
|
114 |
}, |
|
115 |
&cobra.Command{ |
|
116 |
Use: "reblogged-by", |
|
117 |
Short: "Display accounts which reblogged the status", |
|
118 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
119 |
return statusSubcommandRunE(cmd.Name(), args) |
|
120 |
}, |
|
121 |
}, |
|
122 |
&cobra.Command{ |
|
123 |
Use: "favourited-by", |
|
124 |
Aliases: []string{"favorited-by"}, |
|
125 |
Short: "Display accounts which favourited the status", |
|
126 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
127 |
return statusSubcommandRunE(cmd.Name(), args) |
|
128 |
}, |
|
129 |
}, |
|
130 |
&cobra.Command{ |
|
131 |
Use: "delete", |
|
132 |
Aliases: []string{"rm"}, |
|
133 |
Short: "Delete the status", |
|
134 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
135 |
return statusSubcommandRunE(cmd.Name(), args) |
|
136 |
}, |
|
137 |
}, |
|
138 |
statusReblogSubcommand, |
|
139 |
statusFavouriteSubcommand, |
|
140 |
statusPostSubcommand, |
|
141 |
} |
|
142 |
||
143 |
var statusReblogSubcommand = &cobra.Command{ |
|
144 |
Use: "boost", |
|
145 |
Aliases: []string{"reblog"}, |
|
146 |
Short: "Boost (reblog) or unreblog the status", |
|
147 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
148 |
return statusSubcommandRunE(cmd.Name(), args) |
|
149 |
}, |
|
150 |
} |
|
151 |
||
152 |
var statusFavouriteSubcommand = &cobra.Command{ |
|
153 |
Use: "favourite", |
|
154 |
Aliases: []string{"favorite", "fave"}, |
|
155 |
Short: "Mark/unmark the status as favourite", |
|
156 |
RunE: func(cmd *cobra.Command, args []string) error { |
|
157 |
return statusSubcommandRunE(cmd.Name(), args) |
|
158 |
}, |
|
159 |
} |
|
160 |
||
161 |
var statusPostSubcommand = &cobra.Command{ |
|
162 |
Use: "post", |
|
163 |
Aliases: []string{"toot", "pouet"}, |
|
164 |
Short: "Post a message (same as 'madonctl toot')", |
|
165 |
Example: ` madonctl status post --spoiler Warning "Hello, World" |
|
166 |
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
|
167 |
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
|
168 |
madonctl status toot --text-file message.txt |
79
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
169 |
echo "Hello from #madonctl" | madonctl status toot --stdin |
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
170 |
|
bca27c55be9f
Add default visibility setting
Mikael Berthe <mikael@lilotux.net>
parents:
71
diff
changeset
|
171 |
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
|
172 |
'default_visibility' (or with an environmnent variable).`, |
0 | 173 |
RunE: func(cmd *cobra.Command, args []string) error { |
174 |
return statusSubcommandRunE(cmd.Name(), args) |
|
175 |
}, |
|
176 |
} |
|
177 |
||
178 |
func statusSubcommandRunE(subcmd string, args []string) error { |
|
179 |
opt := statusOpts |
|
180 |
||
181 |
var obj interface{} |
|
182 |
var err error |
|
183 |
||
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
184 |
var limOpts *madon.LimitParams |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
185 |
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
|
186 |
limOpts = new(madon.LimitParams) |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
187 |
limOpts.All = opt.all |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
188 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
189 |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
190 |
if opt.limit > 0 { |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
191 |
limOpts.Limit = int(opt.limit) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
192 |
} |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
193 |
/* |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
194 |
if opt.maxID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
195 |
limOpts.MaxID = int64(opt.maxID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
196 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
197 |
if opt.sinceID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
35
diff
changeset
|
198 |
limOpts.SinceID = int64(opt.sinceID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
199 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
200 |
*/ |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
201 |
|
0 | 202 |
switch subcmd { |
203 |
case "show": |
|
204 |
var status *madon.Status |
|
205 |
status, err = gClient.GetStatus(opt.statusID) |
|
206 |
obj = status |
|
207 |
case "context": |
|
208 |
var context *madon.Context |
|
209 |
context, err = gClient.GetStatusContext(opt.statusID) |
|
210 |
obj = context |
|
211 |
case "card": |
|
212 |
var context *madon.Card |
|
213 |
context, err = gClient.GetStatusCard(opt.statusID) |
|
214 |
obj = context |
|
215 |
case "reblogged-by": |
|
216 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
217 |
accountList, err = gClient.GetStatusRebloggedBy(opt.statusID, limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
218 |
if opt.limit > 0 && len(accountList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
219 |
accountList = accountList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
220 |
} |
0 | 221 |
obj = accountList |
222 |
case "favourited-by": |
|
223 |
var accountList []madon.Account |
|
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
224 |
accountList, err = gClient.GetStatusFavouritedBy(opt.statusID, limOpts) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
15
diff
changeset
|
225 |
if opt.limit > 0 && len(accountList) > int(opt.limit) { |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
226 |
accountList = accountList[:opt.limit] |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
227 |
} |
0 | 228 |
obj = accountList |
229 |
case "delete": |
|
230 |
err = gClient.DeleteStatus(opt.statusID) |
|
231 |
case "boost": |
|
232 |
if opt.unset { |
|
233 |
err = gClient.UnreblogStatus(opt.statusID) |
|
234 |
} else { |
|
235 |
err = gClient.ReblogStatus(opt.statusID) |
|
236 |
} |
|
237 |
case "favourite": |
|
238 |
if opt.unset { |
|
239 |
err = gClient.UnfavouriteStatus(opt.statusID) |
|
240 |
} else { |
|
241 |
err = gClient.FavouriteStatus(opt.statusID) |
|
242 |
} |
|
243 |
case "post": // toot |
|
244 |
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
|
245 |
text := strings.Join(args, " ") |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
246 |
if opt.textFilePath != "" { |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
247 |
var b []byte |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
248 |
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
|
249 |
break |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
250 |
} |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
251 |
text = string(b) |
71
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
252 |
} else if opt.stdin { |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
253 |
var b []byte |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
254 |
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
|
255 |
break |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
256 |
} |
67e3234c26a9
Add --stdin to send a message from standard input
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
257 |
text = string(b) |
15
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
258 |
} |
8ac069eaa817
Add option --text-file to send content from a file
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
259 |
s, err = toot(text) |
0 | 260 |
obj = s |
261 |
default: |
|
262 |
return errors.New("statusSubcommand: internal error") |
|
263 |
} |
|
264 |
||
265 |
if err != nil { |
|
266 |
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
|
267 |
os.Exit(1) |
0 | 268 |
} |
269 |
if obj == nil { |
|
270 |
return nil |
|
271 |
} |
|
272 |
||
273 |
p, err := getPrinter() |
|
274 |
if err != nil { |
|
81
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
79
diff
changeset
|
275 |
errPrint("Error: %s", err.Error()) |
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
79
diff
changeset
|
276 |
os.Exit(1) |
0 | 277 |
} |
278 |
return p.PrintObj(obj, nil, "") |
|
279 |
} |