Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --host to shell and open #184

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
}

localIdentifier := workspace.GetLocalIdentifier()
if host {
theFong marked this conversation as resolved.
Show resolved Hide resolved
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 @@
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 @@
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 @@
if workspace.Status != "RUNNING" {
return breverrors.New("Workspace is not running")
}
sshName := string(workspace.GetLocalIdentifier())

localIdentifier := workspace.GetLocalIdentifier()
if host {
localIdentifier += "-host"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

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
Loading