1
- // Copyright © 2018 Jasmin Gacic <[email protected] >
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- // THE SOFTWARE.
20
-
21
1
package facilities
22
2
23
3
import (
4
+ "context"
24
5
"fmt"
25
6
"strings"
26
7
8
+ "github.com/equinix/equinix-sdk-go/services/metalv1"
27
9
"github.com/spf13/cobra"
28
10
)
29
11
30
12
func (c * Client ) Retrieve () * cobra.Command {
31
- return & cobra.Command {
13
+
14
+ retrieveFacilitesCmd := & cobra.Command {
32
15
Use : `get` ,
33
16
Aliases : []string {"list" },
34
17
Short : "Retrieves a list of facilities." ,
@@ -37,23 +20,39 @@ func (c *Client) Retrieve() *cobra.Command {
37
20
metal facilities get` ,
38
21
39
22
RunE : func (cmd * cobra.Command , args []string ) error {
23
+ var (
24
+ facilityList * metalv1.FacilityList
25
+ err error
26
+ )
40
27
cmd .SilenceUsage = true
41
- facilities , _ , err := c .Service .List (c .Servicer .ListOptions (nil , nil ))
28
+
29
+ inc := []metalv1.FindFacilitiesIncludeParameterInner {}
30
+ exc := []metalv1.FindFacilitiesIncludeParameterInner {}
31
+ facilityList , _ , err = c .Service .FindFacilities (context .Background ()).Include (inc ).Exclude (exc ).Execute ()
42
32
if err != nil {
43
33
return fmt .Errorf ("Could not list Facilities: %w" , err )
44
34
}
35
+
36
+ facilities := facilityList .GetFacilities ()
45
37
data := make ([][]string , len (facilities ))
46
38
47
39
for i , facility := range facilities {
48
40
var metro string
49
41
if facility .Metro != nil {
50
- metro = facility .Metro .Code
42
+ metro = facility .Metro .GetCode ()
51
43
}
52
- data [i ] = []string {facility .Name , facility .Code , metro , strings .Join (facility .Features , "," )}
44
+
45
+ facilityFeatures := facility .GetFeatures ()
46
+ var stringFeatures []string
47
+ for _ , feature := range facilityFeatures {
48
+ stringFeatures = append (stringFeatures , string (feature ))
49
+ }
50
+ data [i ] = []string {facility .GetName (), facility .GetCode (), metro , strings .Join (([]string )(stringFeatures ), "," )}
53
51
}
54
52
header := []string {"Name" , "Code" , "Metro" , "Features" }
55
-
56
53
return c .Out .Output (facilities , header , & data )
57
54
},
58
55
}
56
+
57
+ return retrieveFacilitesCmd
59
58
}
0 commit comments