From 850abf1fc4a05a44fd11d6dccc5456b2d3409ac9 Mon Sep 17 00:00:00 2001 From: Nader Khalil Date: Thu, 26 Oct 2023 09:36:32 -0700 Subject: [PATCH] done --- pkg/cmd/hello/hello.go | 9 +++++++++ pkg/cmd/notebook/notebook.go | 38 +++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/hello/hello.go b/pkg/cmd/hello/hello.go index b63ea7a8..183f1b9d 100644 --- a/pkg/cmd/hello/hello.go +++ b/pkg/cmd/hello/hello.go @@ -101,6 +101,15 @@ func TypeItToMeUnskippable(s string) { } } +func TypeItToMeUnskippable27(s string) { + sRunes := []rune(s) + for i := 0; i < len(sRunes); i++ { + time.Sleep(27 * time.Millisecond) + + fmt.Printf("%c", sRunes[i]) + } +} + var wg sync.WaitGroup func RunOnboarding(t *terminal.Terminal, user *entity.User, store HelloStore) error { diff --git a/pkg/cmd/notebook/notebook.go b/pkg/cmd/notebook/notebook.go index de606539..ab216e21 100644 --- a/pkg/cmd/notebook/notebook.go +++ b/pkg/cmd/notebook/notebook.go @@ -5,6 +5,7 @@ import ( "github.com/brevdev/brev-cli/pkg/cmd/hello" "github.com/brevdev/brev-cli/pkg/cmd/portforward" "github.com/brevdev/brev-cli/pkg/cmd/util" + "github.com/brevdev/brev-cli/pkg/entity" breverrors "github.com/brevdev/brev-cli/pkg/errors" "github.com/brevdev/brev-cli/pkg/terminal" "github.com/fatih/color" @@ -20,6 +21,11 @@ type NotebookStore interface { portforward.PortforwardStore } +type WorkspaceResult struct { + Workspace *entity.Workspace // Replace with the actual type of workspace returned by GetUserWorkspaceByNameOrIDErr + Err error +} + func NewCmdNotebook(store NotebookStore, _ *terminal.Terminal) *cobra.Command { cmd := &cobra.Command{ Use: "notebook", @@ -28,27 +34,37 @@ func NewCmdNotebook(store NotebookStore, _ *terminal.Terminal) *cobra.Command { Example: notebookExample, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + // Channel to get the result of the network call + resultCh := make(chan *WorkspaceResult) + + // Start the network call in a goroutine + go func() { + workspace, err := util.GetUserWorkspaceByNameOrIDErr(store, args[0]) + resultCh <- &WorkspaceResult{Workspace: workspace, Err: err} + }() + // Type out the checking message - hello.TypeItToMeUnskippable("Checking to make sure the workspace is running...") + hello.TypeItToMeUnskippable27("Checking to make sure the workspace is running...") + + // Wait for the network call to finish + result := <-resultCh - // Validate if the workspace exists - workspace, err := util.GetUserWorkspaceByNameOrIDErr(store, args[0]) - if err != nil { - return breverrors.WrapAndTrace(err) + if result.Err != nil { + return breverrors.WrapAndTrace(result.Err) } // Check if the workspace is running - if workspace.Status != "RUNNING" { - hello.TypeItToMeUnskippable("The workspace is not running. Please ensure it's in the running state before proceeding.") - return breverrors.WorkspaceNotRunning{Status: workspace.Status} + if result.Workspace.Status != "RUNNING" { + hello.TypeItToMeUnskippable27("The workspace is not running. Please ensure it's in the running state before proceeding.") + return breverrors.WorkspaceNotRunning{Status: result.Workspace.Status} } urlType := color.New(color.FgCyan, color.Bold).SprintFunc() warningType := color.New(color.FgBlack, color.Bold, color.BgCyan).SprintFunc() - hello.TypeItToMeUnskippable("\n" + warningType(" Please keep this terminal open 🤙 ")) + hello.TypeItToMeUnskippable27("\n" + warningType(" Please keep this terminal open 🤙 ")) - hello.TypeItToMeUnskippable("\nClick here to go to your Jupyter notebook:\n\t 👉" + urlType("http://localhost:8888") + "👈\n\n\n") + hello.TypeItToMeUnskippable27("\nClick here to go to your Jupyter notebook:\n\t 👉" + urlType("http://localhost:8888") + "👈\n\n\n") // Port forward on 8888 err2 := portforward.RunPortforward(store, args[0], "8888:8888") @@ -57,7 +73,7 @@ func NewCmdNotebook(store NotebookStore, _ *terminal.Terminal) *cobra.Command { } // Print out a link for the user - hello.TypeItToMeUnskippable("Your notebook is accessible at: http://localhost:8888") + hello.TypeItToMeUnskippable27("Your notebook is accessible at: http://localhost:8888") return nil },