@@ -18,6 +18,26 @@ import (
18
18
19
19
type urlsCmd struct {}
20
20
21
+ func (cmd * urlsCmd ) Subcommands () []cli.Command {
22
+ return []cli.Command {
23
+ & listSubCmd {},
24
+ & createSubCmd {},
25
+ & delSubCmd {},
26
+ }
27
+ }
28
+
29
+ func (cmd urlsCmd ) Spec () cli.CommandSpec {
30
+ return cli.CommandSpec {
31
+ Name : "urls" ,
32
+ Usage : "[subcommand] <flags>" ,
33
+ Desc : "interact with environment devurls" ,
34
+ }
35
+ }
36
+
37
+ func (cmd urlsCmd ) Run (fl * pflag.FlagSet ) {
38
+ exitUsage (fl )
39
+ }
40
+
21
41
// DevURL is the parsed json response record for a devURL from cemanager
22
42
type DevURL struct {
23
43
ID string `json:"id"`
@@ -57,6 +77,48 @@ func accessLevelIsValid(level string) bool {
57
77
return ok
58
78
}
59
79
80
+ type listSubCmd struct {
81
+ outputFmt string
82
+ }
83
+
84
+ // Run gets the list of active devURLs from the cemanager for the
85
+ // specified environment and outputs info to stdout.
86
+ func (sub listSubCmd ) Run (fl * pflag.FlagSet ) {
87
+ envName := fl .Arg (0 )
88
+ devURLs := urlList (envName )
89
+
90
+ switch sub .outputFmt {
91
+ case "human" :
92
+ w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 1 , ' ' , tabwriter .TabIndent )
93
+ for _ , devURL := range devURLs {
94
+ fmt .Fprintf (w , "%s\t %d\t %s\n " , devURL .URL , devURL .Port , devURL .Access )
95
+ }
96
+ err := w .Flush ()
97
+ if err != nil {
98
+ flog .Fatal ("failed to flush writer: %v" , err )
99
+ }
100
+ case "json" :
101
+ err := json .NewEncoder (os .Stdout ).Encode (devURLs )
102
+ if err != nil {
103
+ flog .Fatal ("failed to encode devurls to json: %v" , err )
104
+ }
105
+ default :
106
+ exitUsage (fl )
107
+ }
108
+ }
109
+
110
+ func (sub * listSubCmd ) RegisterFlags (fl * pflag.FlagSet ) {
111
+ fl .StringVarP (& sub .outputFmt , "output" , "o" , "human" , "output format (human | json)" )
112
+ }
113
+
114
+ func (sub * listSubCmd ) Spec () cli.CommandSpec {
115
+ return cli.CommandSpec {
116
+ Name : "ls" ,
117
+ Usage : "<env> <flags>" ,
118
+ Desc : "list all devurls" ,
119
+ }
120
+ }
121
+
60
122
type createSubCmd struct {
61
123
access string
62
124
urlname string
@@ -181,14 +243,6 @@ func (sub delSubCmd) Run(fl *pflag.FlagSet) {
181
243
}
182
244
}
183
245
184
- func (cmd urlsCmd ) Spec () cli.CommandSpec {
185
- return cli.CommandSpec {
186
- Name : "urls" ,
187
- Usage : "<env name>" ,
188
- Desc : "get all development urls for external access" ,
189
- }
190
- }
191
-
192
246
// urlList returns the list of active devURLs from the cemanager.
193
247
func urlList (envName string ) []DevURL {
194
248
entClient := requireAuth ()
@@ -217,23 +271,3 @@ func urlList(envName string) []DevURL {
217
271
218
272
return devURLs
219
273
}
220
-
221
- // Run gets the list of active devURLs from the cemanager for the
222
- // specified environment and outputs info to stdout.
223
- func (cmd urlsCmd ) Run (fl * pflag.FlagSet ) {
224
- envName := fl .Arg (0 )
225
- devURLs := urlList (envName )
226
-
227
- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 1 , ' ' , tabwriter .TabIndent )
228
- for _ , devURL := range devURLs {
229
- fmt .Fprintf (w , "%s\t %d\t %s\n " , devURL .URL , devURL .Port , devURL .Access )
230
- }
231
- w .Flush ()
232
- }
233
-
234
- func (cmd * urlsCmd ) Subcommands () []cli.Command {
235
- return []cli.Command {
236
- & createSubCmd {},
237
- & delSubCmd {},
238
- }
239
- }
0 commit comments