Skip to content

feat(cli): support opening devcontainers in vscode #17189

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

Merged
merged 9 commits into from
Apr 3, 2025
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
Prev Previous commit
Next Next commit
chore: suggestions
- Invert an if-condition to reduce how nested the code was.
- Hide `-c` flag for now
  • Loading branch information
DanielleMaywood committed Apr 3, 2025
commit 93bf7b7fb38cdac67ed753d625ace157161ea199
31 changes: 17 additions & 14 deletions cli/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,25 @@ func (r *RootCmd) openVSCode() *serpent.Command {
var foundContainer bool

for _, container := range containers.Containers {
if container.FriendlyName == containerName {
foundContainer = true

if directory == "" {
localFolder, ok := container.Labels["devcontainer.local_folder"]
if !ok {
return xerrors.New("container missing `devcontainer.local_folder` label")
}

directory, ok = container.Volumes[localFolder]
if !ok {
return xerrors.New("container missing volume for `devcontainer.local_folder`")
}
if container.FriendlyName != containerName {
continue
}

foundContainer = true

if directory == "" {
localFolder, ok := container.Labels["devcontainer.local_folder"]
if !ok {
return xerrors.New("container missing `devcontainer.local_folder` label")
}

break
directory, ok = container.Volumes[localFolder]
if !ok {
return xerrors.New("container missing volume for `devcontainer.local_folder`")
}
}

break
}

if !foundContainer {
Expand Down Expand Up @@ -250,6 +252,7 @@ func (r *RootCmd) openVSCode() *serpent.Command {
FlagShorthand: "c",
Description: "Container name to connect to in the workspace.",
Value: serpent.StringOf(&containerName),
Hidden: true, // Hidden until this features is at least in beta.
},
{
Flag: "test.open-error",
Expand Down
3 changes: 0 additions & 3 deletions cli/testdata/coder_open_vscode_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ USAGE:
Open a workspace in VS Code Desktop

OPTIONS:
-c, --container string
Container name to connect to in the workspace.

--generate-token bool, $CODER_OPEN_VSCODE_GENERATE_TOKEN
Generate an auth token and include it in the vscode:// URI. This is
for automagical configuration of VS Code Desktop and not needed if
Expand Down
8 changes: 0 additions & 8 deletions docs/reference/cli/open_vscode.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading