diff --git a/cmd/dashboard.go b/cmd/dashboard.go new file mode 100644 index 0000000..9a7054f --- /dev/null +++ b/cmd/dashboard.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +func newCmdDashboard(cfg *config, openURL openURL) *cobra.Command { + return &cobra.Command{ + Use: "dashboard [flags]", + Args: cobra.NoArgs, + Short: "Open the Buoyant Cloud dashboard", + RunE: func(cmd *cobra.Command, args []string) error { + return openURL(cfg.bcloudServer) + }, + } +} diff --git a/cmd/dashboard_test.go b/cmd/dashboard_test.go new file mode 100644 index 0000000..fe86bcd --- /dev/null +++ b/cmd/dashboard_test.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "testing" +) + +func TestDashboard(t *testing.T) { + cfg := &config{bcloudServer: "http://example.com"} + + var openedUrl string + mockOpen := func(url string) error { + openedUrl = url + return nil + } + + cmd := newCmdDashboard(cfg, mockOpen) + err := cmd.RunE(cmd, nil) + if err != nil { + t.Error(err) + } + + if openedUrl != cfg.bcloudServer { + t.Fatalf("Expected to open url %s, Got %s", cfg.bcloudServer, openedUrl) + } +} diff --git a/cmd/root.go b/cmd/root.go index 720d463..89203e5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,6 +6,7 @@ import ( "github.com/buoyantio/linkerd-buoyant/pkg/version" "github.com/fatih/color" + "github.com/pkg/browser" "github.com/spf13/cobra" "k8s.io/client-go/util/homedir" ) @@ -62,6 +63,7 @@ upgrade, and delete functionality.`, root.AddCommand(newCmdInstall(cfg)) root.AddCommand(newCmdUninstall(cfg)) root.AddCommand(newCmdVersion(cfg)) + root.AddCommand(newCmdDashboard(cfg, browser.OpenURL)) return root }