diff --git a/cli/root.go b/cli/root.go index 95689241cc..4557834a57 100644 --- a/cli/root.go +++ b/cli/root.go @@ -24,6 +24,7 @@ import ( "text/tabwriter" "time" + "github.com/google/uuid" "github.com/mattn/go-isatty" "github.com/mitchellh/go-wordwrap" "golang.org/x/mod/semver" @@ -923,6 +924,9 @@ func splitNamedWorkspace(identifier string) (owner string, workspaceName string, // a bare name (for a workspace owned by the current user) or a "user/workspace" combination, // where user is either a username or UUID. func namedWorkspace(ctx context.Context, client *codersdk.Client, identifier string) (codersdk.Workspace, error) { + if uid, err := uuid.Parse(identifier); err == nil { + return client.Workspace(ctx, uid) + } owner, name, err := splitNamedWorkspace(identifier) if err != nil { return codersdk.Workspace{}, err diff --git a/cli/show.go b/cli/show.go index c1b9956e38..0ef3d4e90f 100644 --- a/cli/show.go +++ b/cli/show.go @@ -1,8 +1,10 @@ package cli import ( + "fmt" "sort" "sync" + "time" "github.com/google/uuid" "golang.org/x/xerrors" @@ -43,11 +45,11 @@ func (r *RootCmd) show() *serpent.Command { if err != nil { return xerrors.Errorf("get workspace: %w", err) } - options := cliui.WorkspaceResourcesOptions{ WorkspaceName: workspace.Name, ServerVersion: buildInfo.Version, ShowDetails: details, + 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), } if workspace.LatestBuild.Status == codersdk.WorkspaceStatusRunning { // Get listening ports for each agent. @@ -55,7 +57,6 @@ func (r *RootCmd) show() *serpent.Command { options.ListeningPorts = ports options.Devcontainers = devcontainers } - return cliui.WorkspaceResources(inv.Stdout, workspace.LatestBuild.Resources, options) }, } diff --git a/cli/show_test.go b/cli/show_test.go index 36a5824174..46213194f9 100644 --- a/cli/show_test.go +++ b/cli/show_test.go @@ -2,6 +2,7 @@ package cli_test import ( "bytes" + "fmt" "testing" "time" @@ -15,6 +16,7 @@ import ( "github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/pty/ptytest" + "github.com/coder/coder/v2/testutil" ) func TestShow(t *testing.T) { @@ -28,7 +30,7 @@ func TestShow(t *testing.T) { coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) workspace := coderdtest.CreateWorkspace(t, member, template.ID) - coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) + build := coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) args := []string{ "show", @@ -38,26 +40,30 @@ func TestShow(t *testing.T) { clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) pty := ptytest.New(t).Attach(inv) + ctx := testutil.Context(t, testutil.WaitShort) go func() { defer close(doneChan) - err := inv.Run() + err := inv.WithContext(ctx).Run() assert.NoError(t, err) }() matches := []struct { match string write string }{ + {match: fmt.Sprintf("%s/%s", workspace.OwnerName, workspace.Name)}, + {match: fmt.Sprintf("(%s since ", build.Status)}, + {match: fmt.Sprintf("%s:%s", workspace.TemplateName, workspace.LatestBuild.TemplateVersionName)}, {match: "compute.main"}, {match: "smith (linux, i386)"}, {match: "coder ssh " + workspace.Name}, } for _, m := range matches { - pty.ExpectMatch(m.match) + pty.ExpectMatchContext(ctx, m.match) if len(m.write) > 0 { pty.WriteLine(m.write) } } - <-doneChan + _ = testutil.TryReceive(ctx, t, doneChan) }) }