-
Notifications
You must be signed in to change notification settings - Fork 903
feat: Improve resource preview and first-time experience #946
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
85745ab
Improve CLI documentation
kylecarbs e8258ea
feat: Allow workspace resources to attach multiple agents
kylecarbs 6abc4a4
Merge branch 'updatetfprovider' into clihelp
kylecarbs b0cb66d
Add tree view
kylecarbs 6ed0bc0
Improve table UI
kylecarbs 3ad0766
feat: Allow workspace resources to attach multiple agents
kylecarbs 9cbadef
Merge branch 'updatetfprovider' into clihelp
kylecarbs 4496f36
Rename `tunnel` to `skip-tunnel`
kylecarbs 65c19bd
Add disclaimer about editing templates
kylecarbs c50d170
Add help to template create
kylecarbs 326f2d5
Improve workspace create flow
kylecarbs 008ba69
Add end-to-end test for config-ssh
kylecarbs 71e4544
Improve testing of config-ssh
kylecarbs 8fecb67
Fix workspace list
kylecarbs 3e31c06
Merge branch 'main' into clihelp
kylecarbs 677686b
Fix config ssh tests
kylecarbs 603bd90
Update cli/configssh.go
kylecarbs 2a6c607
Fix requested changes
kylecarbs fec214d
Merge branch 'clihelp' of github.com:coder/coder into clihelp
kylecarbs f397afc
Remove socat requirement
kylecarbs 683f87e
Fix resources not reading in TTY
kylecarbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package cliui | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"sort" | ||
"strconv" | ||
|
||
"github.com/jedib0t/go-pretty/v6/table" | ||
|
||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
|
||
type WorkspaceResourcesOptions struct { | ||
WorkspaceName string | ||
HideAgentState bool | ||
HideAccess bool | ||
Title string | ||
} | ||
|
||
// WorkspaceResources displays the connection status and tree-view of provided resources. | ||
// ┌────────────────────────────────────────────────────────────────────────────┐ | ||
// │ RESOURCE STATUS ACCESS │ | ||
// ├────────────────────────────────────────────────────────────────────────────┤ | ||
// │ google_compute_disk.root persistent │ | ||
// ├────────────────────────────────────────────────────────────────────────────┤ | ||
// │ google_compute_instance.dev ephemeral │ | ||
// │ └─ dev (linux, amd64) ⦾ connecting [10s] coder ssh dev.dev │ | ||
// ├────────────────────────────────────────────────────────────────────────────┤ | ||
// │ kubernetes_pod.dev ephemeral │ | ||
// │ ├─ go (linux, amd64) ⦿ connected coder ssh dev.go │ | ||
// │ └─ postgres (linux, amd64) ⦾ disconnected [4s] coder ssh dev.postgres │ | ||
// └────────────────────────────────────────────────────────────────────────────┘ | ||
func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource, options WorkspaceResourcesOptions) error { | ||
kylecarbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Sort resources by type for consistent output. | ||
sort.Slice(resources, func(i, j int) bool { | ||
return resources[i].Type < resources[j].Type | ||
}) | ||
|
||
// Address on stop indexes whether a resource still exists when in the stopped transition. | ||
addressOnStop := map[string]codersdk.WorkspaceResource{} | ||
for _, resource := range resources { | ||
if resource.Transition != database.WorkspaceTransitionStop { | ||
continue | ||
} | ||
addressOnStop[resource.Address] = resource | ||
} | ||
// Displayed stores whether a resource has already been shown. | ||
// Resources can be stored with numerous states, which we | ||
// process prior to display. | ||
displayed := map[string]struct{}{} | ||
|
||
tableWriter := table.NewWriter() | ||
if options.Title != "" { | ||
tableWriter.SetTitle(options.Title) | ||
} | ||
tableWriter.SetStyle(table.StyleLight) | ||
tableWriter.Style().Options.SeparateColumns = false | ||
row := table.Row{"Resource", "Status"} | ||
if !options.HideAccess { | ||
row = append(row, "Access") | ||
} | ||
tableWriter.AppendHeader(row) | ||
|
||
totalAgents := 0 | ||
for _, resource := range resources { | ||
totalAgents += len(resource.Agents) | ||
} | ||
|
||
for _, resource := range resources { | ||
if resource.Type == "random_string" { | ||
// Hide resources that aren't substantial to a user! | ||
// This is an unfortunate case, and we should allow | ||
// callers to hide resources eventually. | ||
continue | ||
} | ||
if _, shown := displayed[resource.Address]; shown { | ||
// The same resource can have multiple transitions. | ||
continue | ||
} | ||
displayed[resource.Address] = struct{}{} | ||
|
||
// Sort agents by name for consistent output. | ||
sort.Slice(resource.Agents, func(i, j int) bool { | ||
return resource.Agents[i].Name < resource.Agents[j].Name | ||
}) | ||
_, existsOnStop := addressOnStop[resource.Address] | ||
resourceState := "ephemeral" | ||
if existsOnStop { | ||
resourceState = "persistent" | ||
} | ||
// Display a line for the resource. | ||
tableWriter.AppendRow(table.Row{ | ||
Styles.Bold.Render(resource.Type + "." + resource.Name), | ||
Styles.Placeholder.Render(resourceState), | ||
"", | ||
}) | ||
// Display all agents associated with the resource. | ||
for index, agent := range resource.Agents { | ||
sshCommand := "coder ssh " + options.WorkspaceName | ||
if totalAgents > 1 { | ||
sshCommand += "." + agent.Name | ||
} | ||
sshCommand = Styles.Code.Render(sshCommand) | ||
var agentStatus string | ||
if !options.HideAgentState { | ||
switch agent.Status { | ||
case codersdk.WorkspaceAgentConnecting: | ||
since := database.Now().Sub(agent.CreatedAt) | ||
agentStatus = Styles.Warn.Render("⦾ connecting") + " " + | ||
Styles.Placeholder.Render("["+strconv.Itoa(int(since.Seconds()))+"s]") | ||
case codersdk.WorkspaceAgentDisconnected: | ||
since := database.Now().Sub(*agent.DisconnectedAt) | ||
agentStatus = Styles.Error.Render("⦾ disconnected") + " " + | ||
Styles.Placeholder.Render("["+strconv.Itoa(int(since.Seconds()))+"s]") | ||
case codersdk.WorkspaceAgentConnected: | ||
agentStatus = Styles.Keyword.Render("⦿ connected") | ||
} | ||
} | ||
|
||
pipe := "├" | ||
if index == len(resource.Agents)-1 { | ||
pipe = "└" | ||
} | ||
row := table.Row{ | ||
// These tree from a resource! | ||
fmt.Sprintf("%s─ %s (%s, %s)", pipe, agent.Name, agent.OperatingSystem, agent.Architecture), | ||
agentStatus, | ||
} | ||
if !options.HideAccess { | ||
row = append(row, sshCommand) | ||
} | ||
tableWriter.AppendRow(row) | ||
} | ||
tableWriter.AppendSeparator() | ||
} | ||
_, err := fmt.Fprintln(writer, tableWriter.Render()) | ||
return err | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels strange to be doing this in one goroutine and waiting for
conn.Closed()
in another goroutine, just to callDone()
. Can we not do it in one?