9
9
"github.com/jedib0t/go-pretty/v6/table"
10
10
11
11
"github.com/coder/coder/coderd/database"
12
+
12
13
"github.com/coder/coder/codersdk"
13
14
)
14
15
@@ -23,12 +24,12 @@ type WorkspaceResourcesOptions struct {
23
24
// ┌────────────────────────────────────────────────────────────────────────────┐
24
25
// │ RESOURCE STATUS ACCESS │
25
26
// ├────────────────────────────────────────────────────────────────────────────┤
26
- // │ google_compute_disk.root persistent │
27
+ // │ google_compute_disk.root │
27
28
// ├────────────────────────────────────────────────────────────────────────────┤
28
- // │ google_compute_instance.dev ephemeral │
29
+ // │ google_compute_instance.dev │
29
30
// │ └─ dev (linux, amd64) ⦾ connecting [10s] coder ssh dev.dev │
30
31
// ├────────────────────────────────────────────────────────────────────────────┤
31
- // │ kubernetes_pod.dev ephemeral │
32
+ // │ kubernetes_pod.dev │
32
33
// │ ├─ go (linux, amd64) ⦿ connected coder ssh dev.go │
33
34
// │ └─ postgres (linux, amd64) ⦾ disconnected [4s] coder ssh dev.postgres │
34
35
// └────────────────────────────────────────────────────────────────────────────┘
@@ -38,26 +39,16 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
38
39
return resources [i ].Type < resources [j ].Type
39
40
})
40
41
41
- // Address on stop indexes whether a resource still exists when in the stopped transition.
42
- addressOnStop := map [string ]codersdk.WorkspaceResource {}
43
- for _ , resource := range resources {
44
- if resource .Transition != codersdk .WorkspaceTransitionStop {
45
- continue
46
- }
47
- addressOnStop [resource .Type + "." + resource .Name ] = resource
48
- }
49
- // Displayed stores whether a resource has already been shown.
50
- // Resources can be stored with numerous states, which we
51
- // process prior to display.
52
- displayed := map [string ]struct {}{}
53
-
54
42
tableWriter := table .NewWriter ()
55
43
if options .Title != "" {
56
44
tableWriter .SetTitle (options .Title )
57
45
}
58
46
tableWriter .SetStyle (table .StyleLight )
59
47
tableWriter .Style ().Options .SeparateColumns = false
60
- row := table.Row {"Resource" , "Status" }
48
+ row := table.Row {"Resource" }
49
+ if ! options .HideAgentState {
50
+ row = append (row , "Status" )
51
+ }
61
52
if ! options .HideAccess {
62
53
row = append (row , "Access" )
63
54
}
@@ -76,60 +67,52 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
76
67
continue
77
68
}
78
69
resourceAddress := resource .Type + "." + resource .Name
79
- if _ , shown := displayed [resourceAddress ]; shown {
80
- // The same resource can have multiple transitions.
81
- continue
82
- }
83
- displayed [resourceAddress ] = struct {}{}
84
70
85
71
// Sort agents by name for consistent output.
86
72
sort .Slice (resource .Agents , func (i , j int ) bool {
87
73
return resource .Agents [i ].Name < resource .Agents [j ].Name
88
74
})
89
- _ , existsOnStop := addressOnStop [resourceAddress ]
90
- resourceState := "ephemeral"
91
- if existsOnStop {
92
- resourceState = "persistent"
93
- }
75
+
94
76
// Display a line for the resource.
95
77
tableWriter .AppendRow (table.Row {
96
78
Styles .Bold .Render (resourceAddress ),
97
- Styles . Placeholder . Render ( resourceState ) ,
79
+ "" ,
98
80
"" ,
99
81
})
100
82
// Display all agents associated with the resource.
101
83
for index , agent := range resource .Agents {
102
- sshCommand := "coder ssh " + options .WorkspaceName
103
- if totalAgents > 1 {
104
- sshCommand += "." + agent .Name
105
- }
106
- sshCommand = Styles .Code .Render (sshCommand )
107
- var agentStatus string
108
- if ! options .HideAgentState {
109
- switch agent .Status {
110
- case codersdk .WorkspaceAgentConnecting :
111
- since := database .Now ().Sub (agent .CreatedAt )
112
- agentStatus = Styles .Warn .Render ("⦾ connecting" ) + " " +
113
- Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
114
- case codersdk .WorkspaceAgentDisconnected :
115
- since := database .Now ().Sub (* agent .DisconnectedAt )
116
- agentStatus = Styles .Error .Render ("⦾ disconnected" ) + " " +
117
- Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
118
- case codersdk .WorkspaceAgentConnected :
119
- agentStatus = Styles .Keyword .Render ("⦿ connected" )
120
- }
121
- }
122
-
123
84
pipe := "├"
124
85
if index == len (resource .Agents )- 1 {
125
86
pipe = "└"
126
87
}
127
88
row := table.Row {
128
89
// These tree from a resource!
129
90
fmt .Sprintf ("%s─ %s (%s, %s)" , pipe , agent .Name , agent .OperatingSystem , agent .Architecture ),
130
- agentStatus ,
91
+ }
92
+ if ! options .HideAgentState {
93
+ var agentStatus string
94
+ if ! options .HideAgentState {
95
+ switch agent .Status {
96
+ case codersdk .WorkspaceAgentConnecting :
97
+ since := database .Now ().Sub (agent .CreatedAt )
98
+ agentStatus = Styles .Warn .Render ("⦾ connecting" ) + " " +
99
+ Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
100
+ case codersdk .WorkspaceAgentDisconnected :
101
+ since := database .Now ().Sub (* agent .DisconnectedAt )
102
+ agentStatus = Styles .Error .Render ("⦾ disconnected" ) + " " +
103
+ Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
104
+ case codersdk .WorkspaceAgentConnected :
105
+ agentStatus = Styles .Keyword .Render ("⦿ connected" )
106
+ }
107
+ }
108
+ row = append (row , agentStatus )
131
109
}
132
110
if ! options .HideAccess {
111
+ sshCommand := "coder ssh " + options .WorkspaceName
112
+ if totalAgents > 1 {
113
+ sshCommand += "." + agent .Name
114
+ }
115
+ sshCommand = Styles .Code .Render (sshCommand )
133
116
row = append (row , sshCommand )
134
117
}
135
118
tableWriter .AppendRow (row )
0 commit comments