MCPcopy Index your code
hub / github.com/coder/coder / WorkspaceResources

Function WorkspaceResources

cli/cliui/resources.go:49–119  ·  view source on GitHub ↗

WorkspaceResources displays the connection status and tree-view of provided resources. ┌────────────────────────────────────────────────────────────────────────────┐ │ RESOURCE STATUS ACCESS │ ├──────────────────────────────────────────────────────

(writer io.Writer, resources []codersdk.WorkspaceResource, options WorkspaceResourcesOptions)

Source from the content-addressed store, hash-verified

47// │ └─ postgres (linux, amd64) ⦾ disconnected [4s] coder ssh dev.postgres │
48// └────────────────────────────────────────────────────────────────────────────┘
49func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource, options WorkspaceResourcesOptions) error {
50 // Sort resources by type for consistent output.
51 sort.Slice(resources, func(i, j int) bool {
52 return resources[i].Type < resources[j].Type
53 })
54
55 tableWriter := table.NewWriter()
56 if options.Title != "" {
57 tableWriter.SetTitle(options.Title)
58 }
59 tableWriter.SetStyle(table.StyleLight)
60 tableWriter.Style().Options.SeparateColumns = false
61 row := table.Row{"Resource"}
62 if !options.HideAgentState {
63 row = append(row, "Status")
64 row = append(row, "Health")
65 row = append(row, "Version")
66 }
67 if !options.HideAccess {
68 row = append(row, "Access")
69 }
70 tableWriter.AppendHeader(row)
71
72 totalAgents := 0
73 for _, resource := range resources {
74 for _, agent := range resource.Agents {
75 if !agent.ParentID.Valid {
76 totalAgents++
77 }
78 }
79 }
80
81 for _, resource := range resources {
82 if resource.Type == "random_string" {
83 // Hide resources that aren't substantial to a user!
84 // This is an unfortunate case, and we should allow
85 // callers to hide resources eventually.
86 continue
87 }
88 resourceAddress := resource.Type + "." + resource.Name
89
90 // Sort agents by name for consistent output.
91 sort.Slice(resource.Agents, func(i, j int) bool {
92 return resource.Agents[i].Name < resource.Agents[j].Name
93 })
94
95 // Display a line for the resource.
96 tableWriter.AppendRow(table.Row{
97 Bold(resourceAddress),
98 "",
99 "",
100 "",
101 })
102 // Display all agents associated with the resource.
103 agents := slice.Filter(resource.Agents, func(agent codersdk.WorkspaceAgent) bool {
104 return !agent.ParentID.Valid
105 })
106 for index, agent := range agents {

Callers 6

showMethod · 0.92
prepWorkspaceBuildFunction · 0.92
TestWorkspaceResourcesFunction · 0.92
mainFunction · 0.92

Calls 6

FilterFunction · 0.92
BoldFunction · 0.85
renderAgentRowFunction · 0.85
renderListeningPortsFunction · 0.85
renderDevcontainersFunction · 0.85
RenderMethod · 0.65

Tested by 2

TestWorkspaceResourcesFunction · 0.74