-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
105 lines (83 loc) · 2.31 KB
/
list.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package cloud
import (
"fmt"
"strings"
"github.com/gookit/color"
"github.com/spf13/cobra"
"github.com/appbricks/cloud-builder/auth"
"github.com/mevansam/termtables"
cbcli_auth "github.com/appbricks/cloud-builder-cli/auth"
cbcli_config "github.com/appbricks/cloud-builder-cli/config"
)
var listFlags = struct {
region bool
}{}
var listCommand = &cobra.Command{
Use: "list",
Short: "List the public clouds where recipes can be launched.",
Long: `
Show a list of public clouds and region information where recipes can
be launched. To be able to target a recipe to one of these clouds you
need ensure your public account credentials have been configured with
the correct permissions.
`,
PreRun: cbcli_auth.AssertAuthorized(auth.NewRoleMask(auth.Admin), nil),
Run: func(cmd *cobra.Command, args []string) {
if listFlags.region {
ListCloudsByRegion()
} else {
ListClouds()
}
},
}
func ListClouds() {
cloudList := cbcli_config.Config.TargetContext().CloudProviderTemplates()
table := termtables.CreateTable()
table.AddHeaders(
color.OpBold.Render("Name"),
color.OpBold.Render("Description"),
color.OpBold.Render("Configured"),
)
for _, cp := range cloudList {
if cp.IsValid() {
table.AddRow(
cp.Name(),
cp.Description(),
"yes",
)
} else {
table.AddRow(
color.OpFuzzy.Render(cp.Name()),
color.OpFuzzy.Render(cp.Description()),
color.OpFuzzy.Render("no"),
)
}
}
fmt.Printf(
"\nThis Cloud Builder cookbook supports launching recipes in the public clouds listed below.\n\n%s\n",
table.Render())
}
func ListCloudsByRegion() {
cloudList := cbcli_config.Config.TargetContext().CloudProviderTemplates()
fmt.Printf("\nThis Cloud Builder cookbook supports launching recipes in the public cloud regions listed below.\n\n")
for _, cp := range cloudList {
table := termtables.CreateTable()
table.AddHeaders(
color.OpBold.Render("Region Name"),
color.OpBold.Render("Description"),
)
for _, r := range cp.GetRegions() {
table.AddRow(r.Name, r.Description)
}
fmt.Printf(
color.OpBold.Render("%s\n%s\n\n%s\n"),
cp.Description(),
strings.Repeat("=", len(cp.Description())),
table.Render())
}
}
func init() {
flags := listCommand.Flags()
flags.SortFlags = false
flags.BoolVarP(&listFlags.region, "regions", "r", false, "show cloud regions")
}