Skip to content

Commit

Permalink
feat(cli): show workspace health in list (coder#8541)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafredri authored Jul 17, 2023
1 parent 616e1d7 commit dfac074
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"
"time"

"github.com/google/uuid"
Expand All @@ -24,6 +25,7 @@ type workspaceListRow struct {
WorkspaceName string `json:"-" table:"workspace,default_sort"`
Template string `json:"-" table:"template"`
Status string `json:"-" table:"status"`
Healthy string `json:"-" table:"healthy"`
LastBuilt string `json:"-" table:"last built"`
Outdated bool `json:"-" table:"outdated"`
StartsAt string `json:"-" table:"starts at"`
Expand Down Expand Up @@ -51,12 +53,17 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
}
}

healthy := ""
if status == "Starting" || status == "Started" {
healthy = strconv.FormatBool(workspace.Health.Healthy)
}
user := usersByID[workspace.OwnerID]
return workspaceListRow{
Workspace: workspace,
WorkspaceName: user.Username + "/" + workspace.Name,
Template: workspace.TemplateName,
Status: status,
Healthy: healthy,
LastBuilt: durationDisplay(lastBuilt),
Outdated: workspace.Outdated,
StartsAt: autostartDisplay,
Expand Down
5 changes: 3 additions & 2 deletions cli/testdata/coder_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Aliases: ls
-a, --all bool
Specifies whether all workspaces will be listed or not.

-c, --column string-array (default: workspace,template,status,last built,outdated,starts at,stops after)
-c, --column string-array (default: workspace,template,status,healthy,last built,outdated,starts at,stops after)
Columns to display in table output. Available columns: workspace,
template, status, last built, outdated, starts at, stops after.
template, status, healthy, last built, outdated, starts at, stops
after.

-o, --output string (default: table)
Output format. Available formats: table, json.
Expand Down
10 changes: 5 additions & 5 deletions docs/cli/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Specifies whether all workspaces will be listed or not.

### -c, --column

| | |
| ------- | -------------------------------------------------------------------------------- |
| Type | <code>string-array</code> |
| Default | <code>workspace,template,status,last built,outdated,starts at,stops after</code> |
| | |
| ------- | ---------------------------------------------------------------------------------------- |
| Type | <code>string-array</code> |
| Default | <code>workspace,template,status,healthy,last built,outdated,starts at,stops after</code> |

Columns to display in table output. Available columns: workspace, template, status, last built, outdated, starts at, stops after.
Columns to display in table output. Available columns: workspace, template, status, healthy, last built, outdated, starts at, stops after.

### -o, --output

Expand Down

0 comments on commit dfac074

Please sign in to comment.