forked from railwayapp/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.go
More file actions
47 lines (40 loc) · 957 Bytes
/
Copy pathenvironment.go
File metadata and controls
47 lines (40 loc) · 957 Bytes
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
package cmd
import (
"context"
"fmt"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/ui"
)
func (h *Handler) Environment(ctx context.Context, req *entity.CommandRequest) error {
projectID, err := h.cfg.GetProject()
if err != nil {
return err
}
project, err := h.ctrl.GetProject(ctx, projectID)
if err != nil {
return err
}
var environment *entity.Environment
if len(req.Args) > 0 {
// Create new environment
environment, err = h.ctrl.CreateEnvironment(ctx, &entity.CreateEnvironmentRequest{
Name: req.Args[0],
ProjectID: project.Id,
})
if err != nil {
return err
}
fmt.Println("Created Environment ✅\nEnvironment: ", ui.BlueText(ui.Bold(req.Args[0]).String()))
} else {
// Existing environment
environment, err = ui.PromptEnvironments(project.Environments)
if err != nil {
return err
}
}
err = h.cfg.SetEnvironment(environment.Id)
if err != nil {
return err
}
return err
}