-
Notifications
You must be signed in to change notification settings - Fork 224
/
dashboard.go
49 lines (36 loc) · 1.22 KB
/
dashboard.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
package cmd
import (
"fmt"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/client"
"github.com/superfly/flyctl/docstrings"
"github.com/skratchdot/open-golang/open"
)
func newDashboardCommand(client *client.Client) *Command {
dashboardStrings := docstrings.Get("dashboard")
dashboardCmd := BuildCommandKS(nil, runDashboard, dashboardStrings, client, requireSession, requireAppName)
dashboardCmd.Aliases = []string{"dash"}
dashMetricsStrings := docstrings.Get("dashboard.metrics")
BuildCommandKS(dashboardCmd, runDashboardMetrics, dashMetricsStrings, client, requireSession, requireAppName)
return dashboardCmd
}
func runDashboard(ctx *cmdctx.CmdContext) error {
app, err := ctx.Client.API().GetApp(ctx.AppName)
if err != nil {
return err
}
dashURL := "https://fly.io/apps/" + app.Name
return runDashboardOpen(ctx, dashURL)
}
func runDashboardMetrics(ctx *cmdctx.CmdContext) error {
app, err := ctx.Client.API().GetApp(ctx.AppName)
if err != nil {
return err
}
metricsURL := "https://fly.io/apps/" + app.Name + "/metrics"
return runDashboardOpen(ctx, metricsURL)
}
func runDashboardOpen(ctx *cmdctx.CmdContext, url string) error {
fmt.Println("Opening", url)
return open.Run(url)
}