Skip to content

Commit 932a54d

Browse files
tylerfongtheFong
authored andcommitted
added --host to shell and open
1 parent 1d8aa45 commit 932a54d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

pkg/cmd/open/open.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type OpenStore interface {
4848
func NewCmdOpen(t *terminal.Terminal, store OpenStore, noLoginStartStore OpenStore) *cobra.Command {
4949
var waitForSetupToFinish bool
5050
var directory string
51+
var host bool
5152

5253
cmd := &cobra.Command{
5354
Annotations: map[string]string{"ssh": ""},
@@ -63,21 +64,22 @@ func NewCmdOpen(t *terminal.Terminal, store OpenStore, noLoginStartStore OpenSto
6364
if waitForSetupToFinish {
6465
setupDoneString = "------ Done running execs ------"
6566
}
66-
err := runOpenCommand(t, store, args[0], setupDoneString, directory)
67+
err := runOpenCommand(t, store, args[0], setupDoneString, directory, host)
6768
if err != nil {
6869
return breverrors.WrapAndTrace(err)
6970
}
7071
return nil
7172
},
7273
}
74+
cmd.Flags().BoolVarP(&host, "host", "", false, "ssh into the host machine instead of the container")
7375
cmd.Flags().BoolVarP(&waitForSetupToFinish, "wait", "w", false, "wait for setup to finish")
7476
cmd.Flags().StringVarP(&directory, "dir", "d", "", "directory to open")
7577

7678
return cmd
7779
}
7880

7981
// Fetch workspace info, then open code editor
80-
func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, setupDoneString string, directory string) error {
82+
func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, setupDoneString string, directory string, host bool) error {
8183
// todo check if workspace is stopped and start if it if it is stopped
8284
fmt.Println("finding your instance...")
8385
res := refresh.RunRefreshAsync(tstore)
@@ -112,6 +114,9 @@ func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, s
112114
}
113115

114116
localIdentifier := workspace.GetLocalIdentifier()
117+
if host {
118+
localIdentifier += "-host"
119+
}
115120

116121
err = res.Await()
117122
if err != nil {

pkg/cmd/shell/shell.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ShellStore interface {
4242
func NewCmdShell(t *terminal.Terminal, store ShellStore, noLoginStartStore ShellStore) *cobra.Command {
4343
var runRemoteCMD bool
4444
var directory string
45-
45+
var host bool
4646
cmd := &cobra.Command{
4747
Annotations: map[string]string{"ssh": ""},
4848
Use: "shell",
@@ -54,20 +54,21 @@ func NewCmdShell(t *terminal.Terminal, store ShellStore, noLoginStartStore Shell
5454
Args: cmderrors.TransformToValidationError(cmderrors.TransformToValidationError(cobra.ExactArgs(1))),
5555
ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(noLoginStartStore, t),
5656
RunE: func(cmd *cobra.Command, args []string) error {
57-
err := runShellCommand(t, store, args[0], directory)
57+
err := runShellCommand(t, store, args[0], directory, host)
5858
if err != nil {
5959
return breverrors.WrapAndTrace(err)
6060
}
6161
return nil
6262
},
6363
}
64+
cmd.Flags().BoolVarP(&host, "host", "", false, "ssh into the host machine instead of the container")
6465
cmd.Flags().BoolVarP(&runRemoteCMD, "remote", "r", true, "run remote commands")
6566
cmd.Flags().StringVarP(&directory, "dir", "d", "", "override directory to launch shell")
6667

6768
return cmd
6869
}
6970

70-
func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID, directory string) error {
71+
func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID, directory string, host bool) error {
7172
s := t.NewSpinner()
7273
workspace, err := util.GetUserWorkspaceByNameOrIDErr(sstore, workspaceNameOrID)
7374
if err != nil {
@@ -93,7 +94,13 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID,
9394
if workspace.Status != "RUNNING" {
9495
return breverrors.New("Workspace is not running")
9596
}
96-
sshName := string(workspace.GetLocalIdentifier())
97+
98+
localIdentifier := workspace.GetLocalIdentifier()
99+
if host {
100+
localIdentifier += "-host"
101+
}
102+
103+
sshName := string(localIdentifier)
97104

98105
err = refreshRes.Await()
99106
if err != nil {

0 commit comments

Comments
 (0)