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
53 lines (43 loc) · 1.2 KB
/
Copy pathstatus.go
File metadata and controls
53 lines (43 loc) · 1.2 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
52
53
package cmd
import (
"context"
"fmt"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/errors"
"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 err != nil {
return err
}
if project != nil {
fmt.Printf("Project: %s\n", ui.Bold(fmt.Sprint(ui.MagentaText(project.Name))))
if projectCfg.Environment != "" {
fmt.Printf("Environment: %s\n", ui.Bold(fmt.Sprint(ui.BlueText(getEnvironmentNameFromID(projectCfg.Environment, project.Environments)))))
} else {
fmt.Println(ui.RedText("Not connected to an environment"))
}
if len(project.Plugins) > 0 {
fmt.Printf("Plugins:\n")
for i := range project.Plugins {
fmt.Printf("%s\n", ui.Bold(fmt.Sprint(ui.GrayText(project.Plugins[i].Name))))
}
}
} else {
fmt.Println(errors.ProjectConfigNotFound)
}
return nil
}