Skip to content

Commit

Permalink
added --host to shell and open
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerfong committed Feb 25, 2024
1 parent 1d8aa45 commit be0bd1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 7 additions & 2 deletions pkg/cmd/open/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type OpenStore interface {
func NewCmdOpen(t *terminal.Terminal, store OpenStore, noLoginStartStore OpenStore) *cobra.Command {
var waitForSetupToFinish bool
var directory string
var host bool

Check warning on line 51 in pkg/cmd/open/open.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/open/open.go#L51

Added line #L51 was not covered by tests

cmd := &cobra.Command{
Annotations: map[string]string{"ssh": ""},
Expand All @@ -63,21 +64,22 @@ func NewCmdOpen(t *terminal.Terminal, store OpenStore, noLoginStartStore OpenSto
if waitForSetupToFinish {
setupDoneString = "------ Done running execs ------"
}
err := runOpenCommand(t, store, args[0], setupDoneString, directory)
err := runOpenCommand(t, store, args[0], setupDoneString, directory, host)

Check warning on line 67 in pkg/cmd/open/open.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/open/open.go#L67

Added line #L67 was not covered by tests
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
}
cmd.Flags().BoolVarP(&host, "host", "", false, "ssh into the host machine instead of the container")

Check warning on line 74 in pkg/cmd/open/open.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/open/open.go#L74

Added line #L74 was not covered by tests
cmd.Flags().BoolVarP(&waitForSetupToFinish, "wait", "w", false, "wait for setup to finish")
cmd.Flags().StringVarP(&directory, "dir", "d", "", "directory to open")

return cmd
}

// Fetch workspace info, then open code editor
func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, setupDoneString string, directory string) error {
func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, setupDoneString string, directory string, host bool) error {

Check warning on line 82 in pkg/cmd/open/open.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/open/open.go#L82

Added line #L82 was not covered by tests
// todo check if workspace is stopped and start if it if it is stopped
fmt.Println("finding your instance...")
res := refresh.RunRefreshAsync(tstore)
Expand Down Expand Up @@ -112,6 +114,9 @@ func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, s
}

localIdentifier := workspace.GetLocalIdentifier()
if host {
localIdentifier += "-host"
}

Check warning on line 119 in pkg/cmd/open/open.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/open/open.go#L117-L119

Added lines #L117 - L119 were not covered by tests

err = res.Await()
if err != nil {
Expand Down
15 changes: 11 additions & 4 deletions pkg/cmd/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ShellStore interface {
func NewCmdShell(t *terminal.Terminal, store ShellStore, noLoginStartStore ShellStore) *cobra.Command {
var runRemoteCMD bool
var directory string

var host bool

Check warning on line 45 in pkg/cmd/shell/shell.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/shell/shell.go#L45

Added line #L45 was not covered by tests
cmd := &cobra.Command{
Annotations: map[string]string{"ssh": ""},
Use: "shell",
Expand All @@ -54,20 +54,21 @@ func NewCmdShell(t *terminal.Terminal, store ShellStore, noLoginStartStore Shell
Args: cmderrors.TransformToValidationError(cmderrors.TransformToValidationError(cobra.ExactArgs(1))),
ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(noLoginStartStore, t),
RunE: func(cmd *cobra.Command, args []string) error {
err := runShellCommand(t, store, args[0], directory)
err := runShellCommand(t, store, args[0], directory, host)

Check warning on line 57 in pkg/cmd/shell/shell.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/shell/shell.go#L57

Added line #L57 was not covered by tests
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
}
cmd.Flags().BoolVarP(&host, "host", "", false, "ssh into the host machine instead of the container")

Check warning on line 64 in pkg/cmd/shell/shell.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/shell/shell.go#L64

Added line #L64 was not covered by tests
cmd.Flags().BoolVarP(&runRemoteCMD, "remote", "r", true, "run remote commands")
cmd.Flags().StringVarP(&directory, "dir", "d", "", "override directory to launch shell")

return cmd
}

func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID, directory string) error {
func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID, directory string, host bool) error {

Check warning on line 71 in pkg/cmd/shell/shell.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/shell/shell.go#L71

Added line #L71 was not covered by tests
s := t.NewSpinner()
workspace, err := util.GetUserWorkspaceByNameOrIDErr(sstore, workspaceNameOrID)
if err != nil {
Expand All @@ -93,7 +94,13 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID,
if workspace.Status != "RUNNING" {
return breverrors.New("Workspace is not running")
}
sshName := string(workspace.GetLocalIdentifier())

localIdentifier := workspace.GetLocalIdentifier()
if host {
localIdentifier += "-host"
}

Check warning on line 101 in pkg/cmd/shell/shell.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/shell/shell.go#L98-L101

Added lines #L98 - L101 were not covered by tests

sshName := string(localIdentifier)

Check warning on line 103 in pkg/cmd/shell/shell.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/shell/shell.go#L103

Added line #L103 was not covered by tests

err = refreshRes.Await()
if err != nil {
Expand Down

0 comments on commit be0bd1c

Please sign in to comment.