-
Notifications
You must be signed in to change notification settings - Fork 227
/
root.go
140 lines (128 loc) · 3.39 KB
/
root.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package regions
import (
"context"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/spf13/cobra"
)
func New() *cobra.Command {
const (
short = "V1 APPS ONLY: Manage regions"
long = `V1 APPS ONLY (except 'regions list'): Configure the region placement rules for an application.`
)
cmd := command.New("regions", short, long, nil)
cmd.AddCommand(
newRegionsAdd(),
newRegionsRemove(),
newRegionsSet(),
newRegionsBackup(),
newRegionsList(),
)
return cmd
}
func newRegionsAdd() *cobra.Command {
const (
short = `V1 APPS ONLY: Allow the app to run in the provided regions`
long = `V1 APPS ONLY: Allow the app to run in one or more regions`
)
cmd := command.New("add REGION [REGION...]", short, long, runRegionsAdd,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.MinimumNArgs(1)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
flag.JSONOutput(),
flag.String{Name: "group", Description: "The process group to add the region to"},
)
return cmd
}
func newRegionsRemove() *cobra.Command {
const (
short = `V1 APPS ONLY: Prevent the app from running in the provided regions`
long = `V1 APPS ONLY: Prevent the app from running in the provided regions`
)
cmd := command.New("remove REGION [REGION...]", short, long, runRegionsRemove,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.MinimumNArgs(1)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
flag.JSONOutput(),
flag.String{Name: "group", Description: "The process group to add the region to"},
)
return cmd
}
func newRegionsSet() *cobra.Command {
const (
short = `V1 APPS ONLY: Sets the region pool with provided regions`
long = `V1 APPS ONLY: Sets the region pool with provided regions`
)
cmd := command.New("set REGION [REGION...]", short, long, runRegionsSet,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.MinimumNArgs(1)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
flag.JSONOutput(),
flag.String{Name: "group", Description: "The process group to add the region to"},
)
return cmd
}
func newRegionsBackup() *cobra.Command {
const (
short = `V1 APPS ONLY: Sets the backup region pool with provided regions`
long = `V1 APPS ONLY: Sets the backup region pool with provided regions`
)
cmd := command.New("backup REGION [REGION...]", short, long, runRegionsBackup,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.MinimumNArgs(1)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
flag.JSONOutput(),
)
return cmd
}
func newRegionsList() *cobra.Command {
const (
short = `Shows the list of regions the app is allowed to run in`
long = `Shows the list of regions the app is allowed to run in`
)
cmd := command.New("list", short, long, runRegionsList,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.NoArgs
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.JSONOutput(),
)
return cmd
}
func runRegionsList(ctx context.Context) error {
appName := appconfig.NameFromContext(ctx)
apiClient := client.FromContext(ctx).API()
app, err := apiClient.GetAppCompact(ctx, appName)
if err != nil {
return err
}
if app.PlatformVersion == "nomad" {
return v1RunRegionsList(ctx)
}
return v2RunRegionsList(ctx)
}