Skip to content

Commit 93bf7b7

Browse files
chore: suggestions
- Invert an if-condition to reduce how nested the code was. - Hide `-c` flag for now
1 parent 9cc49f8 commit 93bf7b7

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

cli/open.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,25 @@ func (r *RootCmd) openVSCode() *serpent.Command {
123123
var foundContainer bool
124124

125125
for _, container := range containers.Containers {
126-
if container.FriendlyName == containerName {
127-
foundContainer = true
128-
129-
if directory == "" {
130-
localFolder, ok := container.Labels["devcontainer.local_folder"]
131-
if !ok {
132-
return xerrors.New("container missing `devcontainer.local_folder` label")
133-
}
134-
135-
directory, ok = container.Volumes[localFolder]
136-
if !ok {
137-
return xerrors.New("container missing volume for `devcontainer.local_folder`")
138-
}
126+
if container.FriendlyName != containerName {
127+
continue
128+
}
129+
130+
foundContainer = true
131+
132+
if directory == "" {
133+
localFolder, ok := container.Labels["devcontainer.local_folder"]
134+
if !ok {
135+
return xerrors.New("container missing `devcontainer.local_folder` label")
139136
}
140137

141-
break
138+
directory, ok = container.Volumes[localFolder]
139+
if !ok {
140+
return xerrors.New("container missing volume for `devcontainer.local_folder`")
141+
}
142142
}
143+
144+
break
143145
}
144146

145147
if !foundContainer {
@@ -250,6 +252,7 @@ func (r *RootCmd) openVSCode() *serpent.Command {
250252
FlagShorthand: "c",
251253
Description: "Container name to connect to in the workspace.",
252254
Value: serpent.StringOf(&containerName),
255+
Hidden: true, // Hidden until this features is at least in beta.
253256
},
254257
{
255258
Flag: "test.open-error",

cli/testdata/coder_open_vscode_--help.golden

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ USAGE:
66
Open a workspace in VS Code Desktop
77

88
OPTIONS:
9-
-c, --container string
10-
Container name to connect to in the workspace.
11-
129
--generate-token bool, $CODER_OPEN_VSCODE_GENERATE_TOKEN
1310
Generate an auth token and include it in the vscode:// URI. This is
1411
for automagical configuration of VS Code Desktop and not needed if

docs/reference/cli/open_vscode.md

-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)