-
Notifications
You must be signed in to change notification settings - Fork 240
/
dashboard.go
54 lines (40 loc) · 1.08 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
50
51
52
53
54
package redis
import (
"context"
"fmt"
"github.com/skratchdot/open-golang/open"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/gql"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/iostreams"
)
func newDashboard() (cmd *cobra.Command) {
const (
long = `View your Upstash Redis databases on the Upstash web console`
short = long
usage = "dashboard <org_slug>"
)
cmd = command.New(usage, short, long, runDashboard, command.RequireSession)
flag.Add(cmd)
cmd.Args = cobra.ExactArgs(1)
return cmd
}
func runDashboard(ctx context.Context) (err error) {
var (
io = iostreams.FromContext(ctx)
client = client.FromContext(ctx).API().GenqClient
)
orgSlug := flag.FirstArg(ctx)
result, err := gql.GetOrganization(ctx, client, orgSlug)
if err != nil {
return err
}
url := result.Organization.AddOnSsoLink
fmt.Fprintf(io.Out, "Opening %s ...\n", url)
if err := open.Run(url); err != nil {
return fmt.Errorf("failed opening %s: %w", url, err)
}
return
}