@@ -17,6 +17,7 @@ import (
1717 "github.com/brevdev/brev-cli/pkg/store"
1818 "github.com/brevdev/brev-cli/pkg/terminal"
1919 "github.com/brevdev/brev-cli/pkg/writeconnectionevent"
20+ "github.com/samber/mo"
2021
2122 "github.com/spf13/cobra"
2223)
@@ -38,6 +39,8 @@ type ShellStore interface {
3839
3940func NewCmdShell (t * terminal.Terminal , store ShellStore , noLoginStartStore ShellStore ) * cobra.Command {
4041 var runRemoteCMD bool
42+ var directory string
43+
4144 cmd := & cobra.Command {
4245 Annotations : map [string ]string {"ssh" : "" },
4346 Use : "shell" ,
@@ -48,19 +51,20 @@ func NewCmdShell(t *terminal.Terminal, store ShellStore, noLoginStartStore Shell
4851 Args : cmderrors .TransformToValidationError (cmderrors .TransformToValidationError (cobra .ExactArgs (1 ))),
4952 ValidArgsFunction : completions .GetAllWorkspaceNameCompletionHandler (noLoginStartStore , t ),
5053 RunE : func (cmd * cobra.Command , args []string ) error {
51- err := runShellCommand (t , store , args [0 ])
54+ err := runShellCommand (t , store , args [0 ], directory )
5255 if err != nil {
5356 return breverrors .WrapAndTrace (err )
5457 }
5558 return nil
5659 },
5760 }
5861 cmd .Flags ().BoolVarP (& runRemoteCMD , "remote" , "r" , true , "run remote commands" )
62+ cmd .Flags ().StringVarP (& directory , "dir" , "d" , "" , "override directory to launch shell" )
5963
6064 return cmd
6165}
6266
63- func runShellCommand (t * terminal.Terminal , sstore ShellStore , workspaceNameOrID string ) error {
67+ func runShellCommand (t * terminal.Terminal , sstore ShellStore , workspaceNameOrID , directory string ) error {
6468 res := refresh .RunRefreshAsync (sstore )
6569
6670 workspace , err := util .GetUserWorkspaceByNameOrIDErr (sstore , workspaceNameOrID )
@@ -96,7 +100,7 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID
96100 // legacy environments wont support this and cause errrors,
97101 // but we don't want to block the user from using the shell
98102 _ = writeconnectionevent .WriteWCEOnEnv (sstore , workspace .DNS )
99- err = runSSH (workspace , sshName )
103+ err = runSSH (workspace , sshName , directory )
100104 if err != nil {
101105 return breverrors .WrapAndTrace (err )
102106 }
@@ -123,10 +127,11 @@ func waitForSSHToBeAvailable(sshAlias string) error {
123127 }
124128}
125129
126- func runSSH (workspace * entity.Workspace , sshAlias string ) error {
130+ func runSSH (workspace * entity.Workspace , sshAlias , directory string ) error {
127131 sshCmd := exec .Command ("ssh" , sshAlias )
132+ path := mo .Some (directory ).OrElse (workspace .GetProjectFolderPath ())
128133 if workspace .GetProjectFolderPath () != "" {
129- sshCmd = exec .Command ("ssh" , "-t" , sshAlias , "cd" , workspace . GetProjectFolderPath () , ";" , "$SHELL" ) //nolint:gosec //this is being run on a user's machine so we're not concerned about shell injection
134+ sshCmd = exec .Command ("ssh" , "-t" , sshAlias , "cd" , path , ";" , "$SHELL" ) //nolint:gosec //this is being run on a user's machine so we're not concerned about shell injection
130135 }
131136 sshCmd .Stderr = os .Stderr
132137 sshCmd .Stdout = os .Stdout
0 commit comments