Skip to content

Commit

Permalink
devbox: Fix opening a specific remote folder
Browse files Browse the repository at this point in the history
  • Loading branch information
pavolmarko committed Jul 11, 2024
1 parent 9e1191b commit 38b56a7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/cli/cmd/devbox/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 38b56a7

Please sign in to comment.