-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathregions.go
54 lines (42 loc) · 1.13 KB
/
regions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package commands
import (
"io"
"github.com/bryanl/doit"
"github.com/bryanl/doit/Godeps/_workspace/src/github.com/digitalocean/godo"
"github.com/bryanl/doit/Godeps/_workspace/src/github.com/spf13/cobra"
)
// Region creates the region commands heirarchy.
func Region() *cobra.Command {
cmd := &cobra.Command{
Use: "region",
Short: "region commands",
Long: "region is used to access region commands",
}
cmdRegionList := cmdBuilder(RunRegionList, "list", "list regions", writer)
cmd.AddCommand(cmdRegionList)
return cmd
}
// RunRegionList all regions.
func RunRegionList(ns string, out io.Writer) error {
client := doit.DoitConfig.GetGodoClient()
f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) {
list, resp, err := client.Regions.List(opt)
if err != nil {
return nil, nil, err
}
si := make([]interface{}, len(list))
for i := range list {
si[i] = list[i]
}
return si, resp, err
}
si, err := doit.PaginateResp(f)
if err != nil {
return err
}
list := make([]godo.Region, len(si))
for i := range si {
list[i] = si[i].(godo.Region)
}
return doit.DisplayOutput(list, out)
}