- Notifications
You must be signed in to change notification settings - Fork948
feat(cli): improve devcontainer support forcoder show
#18793
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
ea9d210
eb04c1a
5519faa
1e5234c
f5fa73c
6bfa223
4d01a60
2eab390
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,16 +8,26 @@ import ( | ||
"github.com/google/uuid" | ||
"github.com/coder/coder/v2/agent/agentcontainers" | ||
"github.com/coder/coder/v2/cli/cliui" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/serpent" | ||
) | ||
func (r *RootCmd) show() *serpent.Command { | ||
client := new(codersdk.Client) | ||
var details bool | ||
return &serpent.Command{ | ||
Use: "show <workspace>", | ||
Short: "Display details of a workspace's resources and agents", | ||
Options: serpent.OptionSet{ | ||
{ | ||
Flag: "details", | ||
Description: "Show full error messages and additional details.", | ||
Default: "false", | ||
Value: serpent.BoolOf(&details), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggestion: explicit default value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I added it but it changes the CLI output to show default false. Not sure I like that to be honest since it's kinda clear that that's already the case. But either way works for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm easy either way, having an explicit default is easier to read but if it negatively impacts the help output we can skip it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It doesn't seem so bad to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Alright. IMO it's somewhat of a bug in serpent, doesn't really make sense to render the two cases differently and it could already inherit the default value from the current value of the variable given as pointer | ||
}, | ||
}, | ||
Middleware: serpent.Chain( | ||
serpent.RequireNArgs(1), | ||
r.InitClient(client), | ||
@@ -35,13 +45,15 @@ func (r *RootCmd) show() *serpent.Command { | ||
options := cliui.WorkspaceResourcesOptions{ | ||
WorkspaceName: workspace.Name, | ||
ServerVersion: buildInfo.Version, | ||
ShowDetails: details, | ||
} | ||
if workspace.LatestBuild.Status == codersdk.WorkspaceStatusRunning { | ||
// Get listening ports for each agent. | ||
ports, devcontainers := fetchRuntimeResources(inv, client, workspace.LatestBuild.Resources...) | ||
options.ListeningPorts = ports | ||
options.Devcontainers = devcontainers | ||
} | ||
return cliui.WorkspaceResources(inv.Stdout, workspace.LatestBuild.Resources, options) | ||
}, | ||
} | ||
@@ -68,13 +80,17 @@ func fetchRuntimeResources(inv *serpent.Invocation, client *codersdk.Client, res | ||
ports[agent.ID] = lp | ||
mu.Unlock() | ||
}() | ||
if agent.ParentID.Valid { | ||
continue | ||
} | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
dc, err := client.WorkspaceAgentListContainers(inv.Context(), agent.ID, map[string]string{ | ||
// Labels set by VSCode Remote Containers and @devcontainers/cli. | ||
agentcontainers.DevcontainerConfigFileLabel: "", | ||
agentcontainers.DevcontainerLocalFolderLabel: "", | ||
}) | ||
if err != nil { | ||
cliui.Warnf(inv.Stderr, "Failed to get devcontainers for agent %s: %v", agent.Name, err) | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.