-
Notifications
You must be signed in to change notification settings - Fork 223
/
regions.go
81 lines (67 loc) · 1.74 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
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
package platform
import (
"context"
"fmt"
"sort"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/render"
)
// Hardcoded list of regions with GPUs
// TODO: fetch this list from the graphql endpoint once it is there
var gpuRegions = []string{"iad", "sjc", "syd", "ams"}
func newRegions() (cmd *cobra.Command) {
const (
long = `View a list of regions where Fly has edges and/or datacenters
`
short = "List regions"
)
cmd = command.New("regions", short, long, runRegions,
command.RequireSession,
)
cmd.Args = cobra.NoArgs
flag.Add(cmd, flag.JSONOutput())
return
}
func runRegions(ctx context.Context) error {
client := flyutil.ClientFromContext(ctx)
regions, _, err := client.PlatformRegions(ctx)
if err != nil {
return fmt.Errorf("failed retrieving regions: %w", err)
}
sort.Slice(regions, func(i, j int) bool {
return regions[i].Name < regions[j].Name
})
out := iostreams.FromContext(ctx).Out
if config.FromContext(ctx).JSONOutput {
return render.JSON(out, regions)
}
var rows [][]string
for _, region := range regions {
gateway := ""
if region.GatewayAvailable {
gateway = "✓"
}
paidPlan := ""
if region.RequiresPaidPlan {
paidPlan = "✓"
}
gpuAvailable := ""
if slices.Contains(gpuRegions, region.Code) {
gpuAvailable = "✓"
}
rows = append(rows, []string{
region.Name,
region.Code,
gateway,
paidPlan,
gpuAvailable,
})
}
return render.Table(out, "", rows, "Name", "Code", "Gateway", "Launch Plan + Only", "GPUs")
}