forked from railwayapp/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.go
More file actions
51 lines (41 loc) · 1.17 KB
/
Copy pathstatus.go
File metadata and controls
51 lines (41 loc) · 1.17 KB
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
package cmd
import (
"context"
"fmt"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/ui"
)
func getEnvironmentNameFromID(id string, environments []*entity.Environment) string {
for _, environment := range environments {
if environment.Id == id {
return environment.Name
}
}
return ""
}
func (h *Handler) Status(ctx context.Context, req *entity.CommandRequest) error {
projectCfg, err := h.cfg.GetProjectConfigs()
if err != nil {
return err
}
project, err := h.ctrl.GetProject(ctx, projectCfg.Project)
if project != nil {
fmt.Printf("Project: %s\n", ui.MagentaText(project.Name))
if projectCfg.Environment != "" {
fmt.Printf("Environment: %s\n", ui.BlueText(getEnvironmentNameFromID(projectCfg.Environment, project.Environments)))
} else {
fmt.Println("Not connected to an environment")
}
if len(project.Plugins) > 0 {
fmt.Printf("Plugins:\n")
for i := range project.Plugins {
fmt.Printf("%s\n", ui.GrayText(project.Plugins[i].Name))
}
}
} else if projectCfg.Project != "" {
fmt.Println("Project not found. Maybe you need to login?")
} else {
fmt.Println("Not connected to a project. Run railway init.")
}
return nil
}