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
67 lines (55 loc) · 1.49 KB
/
Copy pathstatus.go
File metadata and controls
67 lines (55 loc) · 1.49 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"context"
"fmt"
"github.com/railwayapp/cli/entity"
)
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 {
user, err := h.ctrl.GetUser(ctx)
projectCfg, err := h.cfg.GetProjectConfigs()
if err != nil {
return err
}
project, err := h.ctrl.GetProject(ctx, projectCfg.Project)
if user != nil {
// user names can be empty
if user.Name == "" {
fmt.Println(fmt.Sprintf("Logged in as: %s", user.Email))
} else {
fmt.Println(fmt.Sprintf("Logged in as: %s (%s)", user.Name, user.Email))
}
} else {
fmt.Println("Not logged in. Run railway login")
}
if project != nil {
fmt.Println("Connected to project", project.Name)
if projectCfg.Environment != "" {
fmt.Println("Using environment", getEnvironmentNameFromID(projectCfg.Environment, project.Environments))
} else {
fmt.Println("Not connected to an environment")
}
if len(project.Plugins) > 0 {
fmt.Println("Plugins added:")
for i := range project.Plugins {
fmt.Println(project.Plugins[i].Name)
}
}
} else if projectCfg.Project != "" {
if user != nil {
fmt.Println("Project not found")
} else {
fmt.Println("Project not found. Maybe you need to login?")
}
} else {
fmt.Println("Not connected to a project. Run railway init.")
}
return nil
}