Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
naderkhalil committed Oct 26, 2023
1 parent 023cce1 commit 850abf1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
9 changes: 9 additions & 0 deletions pkg/cmd/hello/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 27 additions & 11 deletions pkg/cmd/notebook/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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")
Expand All @@ -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
},
Expand Down

0 comments on commit 850abf1

Please sign in to comment.