-
Notifications
You must be signed in to change notification settings - Fork 100
/
cmd_ui.go
62 lines (53 loc) · 1.42 KB
/
cmd_ui.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
package system
import (
"fmt"
"os/exec"
"runtime"
"github.com/noobaa/noobaa-operator/v2/pkg/util"
"github.com/spf13/cobra"
)
// CmdUI returns a CLI command
func CmdUI() *cobra.Command {
cmd := &cobra.Command{
Use: "ui",
Short: "Open the NooBaa UI",
Run: RunUI,
}
return cmd
}
// RunUI runs a CLI command
func RunUI(cmd *cobra.Command, args []string) {
log := util.Logger()
sysClient, err := Connect(true)
if err != nil {
log.Fatalf("❌ %s", err)
}
mgmtURL := sysClient.MgmtURL.String()
fmt.Printf("\n")
fmt.Printf("NooBaa UI (credentials unless using Openshift SSO):\n")
fmt.Printf("url : %s\n", mgmtURL)
fmt.Printf("email : %s\n", sysClient.SecretAdmin.StringData["email"])
fmt.Printf("password : %s\n", sysClient.SecretAdmin.StringData["password"])
fmt.Printf("\n")
fmt.Printf("\n")
fmt.Printf("---> NOTE: Keep this process running while using the UI ...")
fmt.Printf("---> <Ctrl-C> to stop")
fmt.Printf("\n")
fmt.Printf("\n")
OpenURLInBrowser(mgmtURL)
stopChan := make(chan int)
<-stopChan
}
// OpenURLInBrowser opens the url in a browser according to the current OS
func OpenURLInBrowser(u string) error {
switch runtime.GOOS {
case "darwin":
return exec.Command("open", u).Start()
case "linux":
return exec.Command("xdg-open", u).Start()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", u).Start()
default:
return fmt.Errorf("unsupported platform")
}
}