-
Notifications
You must be signed in to change notification settings - Fork 240
/
root.go
65 lines (58 loc) · 1.55 KB
/
root.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package dashboard
import (
"context"
"fmt"
"github.com/skratchdot/open-golang/open"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/iostreams"
)
func New() *cobra.Command {
const (
short = "Open web browser on Fly Web UI for this app"
long = `Open web browser on Fly Web UI for this application`
)
cmd := command.New("dashboard", short, long, runDashboard,
command.RequireSession,
command.RequireAppName,
)
cmd.AddCommand(
newDashboardMetrics(),
)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
)
cmd.Aliases = []string{"dash"}
return cmd
}
func newDashboardMetrics() *cobra.Command {
const (
short = "Open web browser on Fly Web UI for this app's metrics"
long = `Open web browser on Fly Web UI for this application's metrics`
)
cmd := command.New("metrics", short, long, runDashboardMetrics,
command.RequireSession,
command.RequireAppName,
)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
)
return cmd
}
func runDashboard(ctx context.Context) error {
appName := appconfig.NameFromContext(ctx)
return runDashboardOpen(ctx, "https://fly.io/apps/"+appName)
}
func runDashboardMetrics(ctx context.Context) error {
appName := appconfig.NameFromContext(ctx)
return runDashboardOpen(ctx, "https://fly.io/apps/"+appName+"/metrics")
}
func runDashboardOpen(ctx context.Context, url string) error {
io := iostreams.FromContext(ctx)
fmt.Fprintln(io.Out, "Opening", url)
return open.Run(url)
}