diff --git a/internal/cli/cmd/devbox/vscode.go b/internal/cli/cmd/devbox/vscode.go index 74b1b2e70..10b6be23b 100644 --- a/internal/cli/cmd/devbox/vscode.go +++ b/internal/cli/cmd/devbox/vscode.go @@ -9,20 +9,27 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "github.com/spf13/cobra" "namespacelabs.dev/foundation/internal/cli/fncobra" ) +const ( + // TODO this should not be hardcoded long term + DEVBOX_HOME_DIR = "/home/dev" +) + func newVscodeCommand() *cobra.Command { cmd := &cobra.Command{ Use: "code tag [path]", Short: "Initiate a vscode session on the devbox 'tag'.", - Long: "Initiate a vscode session on the devbox 'tag'. If 'path' is given, vscode remote is opened in that path. Otherwise the home directory of the devbox is used as the path.", + Long: "Initiate a vscode session on the devbox 'tag'. If 'path' is given, vscode remote is opened in that path on the devbox. Otherwise the home directory of the devbox is used as the path.", Args: cobra.RangeArgs(1, 2), } cmd.RunE = fncobra.RunE(func(ctx context.Context, args []string) error { + // TODO evaluate if supporting "open specific folder on remote" is useful pathOnRemote := "." if len(args) >= 2 { pathOnRemote = args[1] @@ -52,8 +59,9 @@ func vscodeDevbox(ctx context.Context, tag string, pathOnRemote string) error { // https://code.visualstudio.com/docs/remote/troubleshooting#_connect-to-a-remote-host-from-the-terminal // Note that vscode will offer to install the necessary extension if it's not installed yet. vscodeRemoteSpec := "ssh-remote+" + instance.regionalSshEndpoint + absPathOnRemote := filepath.Join(DEVBOX_HOME_DIR, pathOnRemote) - cmd := exec.Command("code", "--remote", vscodeRemoteSpec, pathOnRemote) + cmd := exec.Command("code", "--remote", vscodeRemoteSpec, absPathOnRemote) cmd.Stdout = os.Stdout cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr