@@ -88,21 +88,21 @@ func (sub listSubCmd) Run(fl *pflag.FlagSet) {
88
88
envName := fl .Arg (0 )
89
89
devURLs := urlList (envName )
90
90
91
+ if len (devURLs ) == 0 {
92
+ return
93
+ }
94
+
91
95
switch sub .outputFmt {
92
96
case "human" :
93
97
w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 1 , ' ' , tabwriter .TabIndent )
94
98
for _ , devURL := range devURLs {
95
99
fmt .Fprintf (w , "%s\t %d\t %s\n " , devURL .URL , devURL .Port , devURL .Access )
96
100
}
97
101
err := w .Flush ()
98
- if err != nil {
99
- flog .Fatal ("failed to flush writer: %v" , err )
100
- }
102
+ requireSuccess (err , "failed to flush writer: %v" , err )
101
103
case "json" :
102
104
err := json .NewEncoder (os .Stdout ).Encode (devURLs )
103
- if err != nil {
104
- flog .Fatal ("failed to encode devurls to json: %v" , err )
105
- }
105
+ requireSuccess (err , "failed to encode devurls to json: %v" , err )
106
106
default :
107
107
exitUsage (fl )
108
108
}
@@ -116,7 +116,7 @@ func (sub *listSubCmd) Spec() cli.CommandSpec {
116
116
return cli.CommandSpec {
117
117
Name : "ls" ,
118
118
Usage : "<env> <flags>" ,
119
- Desc : "list all devurls" ,
119
+ Desc : "list all devurls for a given environment " ,
120
120
}
121
121
}
122
122
@@ -169,7 +169,7 @@ func (sub createSubCmd) Run(fl *pflag.FlagSet) {
169
169
170
170
name = sub .urlname
171
171
if name != "" && ! devURLNameValidRx .MatchString (name ) {
172
- flog .Error ("update devurl: name must be < 64 chars in length, begin with a letter and only contain letters or digits." )
172
+ flog .Fatal ("update devurl: name must be < 64 chars in length, begin with a letter and only contain letters or digits." )
173
173
return
174
174
}
175
175
entClient := requireAuth ()
@@ -180,25 +180,21 @@ func (sub createSubCmd) Run(fl *pflag.FlagSet) {
180
180
if found {
181
181
flog .Info ("Updating devurl for port %v" , port )
182
182
err := entClient .UpdateDevURL (env .ID , urlID , portNum , name , access )
183
- if err != nil {
184
- flog .Error ("update devurl: %s" , err .Error ())
185
- }
183
+ requireSuccess (err , "update devurl: %s" , err )
186
184
} else {
187
185
flog .Info ("Adding devurl for port %v" , port )
188
186
err := entClient .InsertDevURL (env .ID , portNum , name , access )
189
- if err != nil {
190
- flog .Error ("insert devurl: %s" , err .Error ())
191
- }
187
+ requireSuccess (err , "insert devurl: %s" , err )
192
188
}
193
189
}
194
190
195
191
type delSubCmd struct {}
196
192
197
193
func (sub delSubCmd ) Spec () cli.CommandSpec {
198
194
return cli.CommandSpec {
199
- Name : "del " ,
195
+ Name : "rm " ,
200
196
Usage : "<env name> <port>" ,
201
- Desc : "delete a devurl" ,
197
+ Desc : "remove a devurl" ,
202
198
}
203
199
}
204
200
@@ -239,9 +235,7 @@ func (sub delSubCmd) Run(fl *pflag.FlagSet) {
239
235
}
240
236
241
237
err = entClient .DelDevURL (env .ID , urlID )
242
- if err != nil {
243
- flog .Error ("delete devurl: %s" , err .Error ())
244
- }
238
+ requireSuccess (err , "delete devurl: %s" , err )
245
239
}
246
240
247
241
// urlList returns the list of active devURLs from the cemanager.
@@ -253,9 +247,7 @@ func urlList(envName string) []DevURL {
253
247
reqURL := fmt .Sprintf (reqString , entClient .BaseURL , env .ID , entClient .Token )
254
248
255
249
resp , err := http .Get (reqURL )
256
- if err != nil {
257
- flog .Fatal ("%v" , err )
258
- }
250
+ requireSuccess (err , "%v" , err )
259
251
defer resp .Body .Close ()
260
252
261
253
if resp .StatusCode != 200 {
@@ -266,9 +258,7 @@ func urlList(envName string) []DevURL {
266
258
267
259
devURLs := make ([]DevURL , 0 )
268
260
err = dec .Decode (& devURLs )
269
- if err != nil {
270
- flog .Fatal ("%v" , err )
271
- }
261
+ requireSuccess (err , "%v" , err )
272
262
273
263
return devURLs
274
264
}
0 commit comments