-
Notifications
You must be signed in to change notification settings - Fork 240
/
status.go
82 lines (62 loc) · 1.55 KB
/
status.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
package redis
import (
"context"
"strings"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/gql"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
func newStatus() *cobra.Command {
const (
short = "Show status of a Redis database"
long = short + "\n"
usage = "status <name>"
)
cmd := command.New(usage, short, long, runStatus,
command.RequireSession,
)
cmd.Args = cobra.ExactArgs(1)
flag.Add(cmd)
return cmd
}
func runStatus(ctx context.Context) (err error) {
var (
io = iostreams.FromContext(ctx)
name = flag.FirstArg(ctx)
client = client.FromContext(ctx).API().GenqClient
)
response, err := gql.GetAddOn(ctx, client, name)
if err != nil {
return err
}
addOn := response.AddOn
var readRegions string = "None"
if len(addOn.ReadRegions) > 0 {
readRegions = strings.Join(addOn.ReadRegions, ",")
}
options, _ := addOn.Options.(map[string]interface{})
evictionStatus := "Disabled"
if options["eviction"] != nil && options["eviction"].(bool) {
evictionStatus = "Enabled"
}
obj := [][]string{
{
addOn.Id,
addOn.Name,
addOn.AddOnPlan.DisplayName,
addOn.PrimaryRegion,
readRegions,
evictionStatus,
addOn.PublicUrl,
},
}
var cols []string = []string{"ID", "Name", "Plan", "Primary Region", "Read Regions", "Eviction", "Private URL"}
if err = render.VerticalTable(io.Out, "Redis", obj, cols...); err != nil {
return
}
return
}