()
| 16 | ) |
| 17 | |
| 18 | func (r *RootCmd) show() *serpent.Command { |
| 19 | var details bool |
| 20 | return &serpent.Command{ |
| 21 | Use: "show <workspace>", |
| 22 | Short: "Display details of a workspace's resources and agents", |
| 23 | Options: serpent.OptionSet{ |
| 24 | { |
| 25 | Flag: "details", |
| 26 | Description: "Show full error messages and additional details.", |
| 27 | Default: "false", |
| 28 | Value: serpent.BoolOf(&details), |
| 29 | }, |
| 30 | }, |
| 31 | Middleware: serpent.Chain( |
| 32 | serpent.RequireNArgs(1), |
| 33 | ), |
| 34 | Handler: func(inv *serpent.Invocation) error { |
| 35 | client, err := r.InitClient(inv) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | buildInfo, err := client.BuildInfo(inv.Context()) |
| 41 | if err != nil { |
| 42 | return xerrors.Errorf("get server version: %w", err) |
| 43 | } |
| 44 | workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0]) |
| 45 | if err != nil { |
| 46 | return xerrors.Errorf("get workspace: %w", err) |
| 47 | } |
| 48 | options := cliui.WorkspaceResourcesOptions{ |
| 49 | WorkspaceName: workspace.Name, |
| 50 | ServerVersion: buildInfo.Version, |
| 51 | ShowDetails: details, |
| 52 | Title: fmt.Sprintf("%s/%s (%s since %s) %s:%s", workspace.OwnerName, workspace.Name, workspace.LatestBuild.Status, time.Since(workspace.LatestBuild.CreatedAt).Round(time.Second).String(), workspace.TemplateName, workspace.LatestBuild.TemplateVersionName), |
| 53 | } |
| 54 | if workspace.LatestBuild.Status == codersdk.WorkspaceStatusRunning { |
| 55 | // Get listening ports for each agent. |
| 56 | ports, devcontainers := fetchRuntimeResources(inv, client, workspace.LatestBuild.Resources...) |
| 57 | options.ListeningPorts = ports |
| 58 | options.Devcontainers = devcontainers |
| 59 | } |
| 60 | return cliui.WorkspaceResources(inv.Stdout, workspace.LatestBuild.Resources, options) |
| 61 | }, |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func fetchRuntimeResources(inv *serpent.Invocation, client *codersdk.Client, resources ...codersdk.WorkspaceResource) (map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse, map[uuid.UUID]codersdk.WorkspaceAgentListContainersResponse) { |
| 66 | ports := make(map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse) |
no test coverage detected