diff --git a/commands/commands.go b/commands/commands.go index b38b00c..a3f381c 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -35,17 +35,18 @@ DESCRIPTION command shorthand description - help h show the help message. - up u spin up an orchestra sandbox. - down tear down an orchestra sandbox. - name n show the sandbox name. - dash d open the dashboard in a browser. - logs l open the logs in a browser. - web w open the site in a browser. - graphiql g open graphql user interface in a browser. - version v show the version of the sbx cli. - info i show the summary of the sandbox. - progress p open deployment progress in a browser. + help shows the help message. + up u spins up an orchestra sandbox. + down tears down an orchestra sandbox. + name n shows the sandbox name. + dash d opens the dashboard in a browser. + logs l opens the logs in a browser. + web w opens the site in a browser. + graphiql g opens graphql user interface in a browser. + version v shows the version of the sbx cli. + info i shows the summary of the sandbox. + progress p opens deployment progress in a browser. + headlamp h opens headlamp ( kubernetes dashboard ) in a browser. USAGE: @@ -62,7 +63,6 @@ func Commands() map[string]RunFn { "up": up.Run, "u": up.Run, "help": help, - "h": help, "name": name.Run, "n": name.Run, "web": web.Open, @@ -80,5 +80,7 @@ func Commands() map[string]RunFn { "l": logs.Run, "info": summary.Run, "i": summary.Run, + "headlamp": web.OpenHeadlamp, + "h": web.OpenHeadlamp, } } diff --git a/summary/summary.go b/summary/summary.go index 5e36cc3..48f2b74 100644 --- a/summary/summary.go +++ b/summary/summary.go @@ -5,9 +5,9 @@ import ( "github.com/reverbdotcom/sbx/commit" "github.com/reverbdotcom/sbx/name" "github.com/reverbdotcom/sbx/run" - "github.com/reverbdotcom/sbx/web" ) +const template = "https://%s.int.orchestra.rvb.ai/" const summary = `»»» Name: %s SHA: %s @@ -17,6 +17,7 @@ Host: %s Site: sbx w | sbx web Graphiql: sbx g | sbx graphiql +Headlamp: sbx h | sbx headlamp Dash: sbx d | sbx dash Logs: sbx l | sbx logs Deployment: sbx p | sbx progress @@ -46,7 +47,6 @@ func Print(name string) error { var htmlUrl = run.HtmlUrl var headSHA = commit.HeadSHA -var webUrl = web.Url func printSummary(name string) (string, error) { sha, err := headSHA() @@ -59,6 +59,11 @@ func printSummary(name string) (string, error) { summary, name, sha, - webUrl(), + url(), ), nil } + +func url() string { + name, _ := name.Name() + return fmt.Sprintf(template, name) +} diff --git a/summary/summary_test.go b/summary/summary_test.go index 3fd3feb..34a3a68 100644 --- a/summary/summary_test.go +++ b/summary/summary_test.go @@ -10,8 +10,6 @@ func TestPrint(t *testing.T) { name := "sandbox-blake-julian-kevin" headSHA = func() (string, error) { return "head.sha", nil } - webUrl = func() string { return "web.url" } - got, err := printSummary(name) if err != nil { @@ -21,12 +19,13 @@ func TestPrint(t *testing.T) { want := `»»» Name: sandbox-blake-julian-kevin SHA: head.sha -Host: web.url +Host: https://sandbox-lorraine-francisco-jonathan.int.orchestra.rvb.ai/ »»» Site: sbx w | sbx web Graphiql: sbx g | sbx graphiql +Headlamp: sbx h | sbx headlamp Dash: sbx d | sbx dash Logs: sbx l | sbx logs Deployment: sbx p | sbx progress diff --git a/web/web.go b/web/web.go index fea11b1..4880267 100644 --- a/web/web.go +++ b/web/web.go @@ -8,11 +8,14 @@ import ( ) const template = "https://%s.int.orchestra.rvb.ai/" +const headlampTemplate = "https://headlamp.int.preprod.reverb.rvb.ai/c/main/deployments?namespace=%s" var openURL = open.Open func Open() (string, error) { - err := openURL(Url()) + name, _ := nameFn() + url := fmt.Sprintf(template, name) + err := openURL(url) if err != nil { return "", err @@ -39,7 +42,14 @@ func OpenProgress() (string, error) { var nameFn = name.Name -func Url() string { +func OpenHeadlamp() (string, error) { name, _ := nameFn() - return fmt.Sprintf(template, name) + url := fmt.Sprintf(headlampTemplate, name) + err := openURL(url) + + if err != nil { + return "", err + } + + return "", nil } diff --git a/web/web_test.go b/web/web_test.go index a699788..75455f4 100644 --- a/web/web_test.go +++ b/web/web_test.go @@ -6,20 +6,6 @@ import ( "testing" ) -func TestUrl(t *testing.T) { - name := "sandbox-foo-bar-baz" - nameFn = func() (string, error) { return name, nil } - - t.Run("it returns url", func(t *testing.T) { - got := Url() - want := fmt.Sprintf(template, name) - - if got != want { - t.Errorf("got %v, want %v", got, want) - } - }) -} - func TestOpen(t *testing.T) { name := "sandbox-foo-bar-baz" nameFn = func() (string, error) { return name, nil } @@ -113,3 +99,39 @@ func TestOpenProgress(t *testing.T) { } }) } + +func TestOpenHeadlamp(t *testing.T) { + name := "sandbox-foo-bar-baz" + nameFn = func() (string, error) { return name, nil } + + t.Run("it opens url", func(t *testing.T) { + want := fmt.Sprintf(headlampTemplate, name) + + openURL = func(got string) error { + if got != want { + t.Errorf("got %v, want %v", got, want) + } + + return nil + } + + _, err := OpenHeadlamp() + + if err != nil { + t.Errorf("got %v, want nil", err) + } + }) + + t.Run("it returns err", func(t *testing.T) { + openURL = func(_ string) error { + return errors.New("open error") + } + + _, err := OpenHeadlamp() + + want := "open error" + if err.Error() != want { + t.Errorf("got %v, want %v", err, want) + } + }) +}