mirror of https://github.com/coder/coder.git
feat(cli): add daily_cost to `coder ls` (#9200)
This commit is contained in:
parent
e95557890a
commit
6b8102cf4c
16
cli/list.go
16
cli/list.go
|
@ -30,6 +30,7 @@ type workspaceListRow struct {
|
|||
Outdated bool `json:"-" table:"outdated"`
|
||||
StartsAt string `json:"-" table:"starts at"`
|
||||
StopsAfter string `json:"-" table:"stops after"`
|
||||
DailyCost string `json:"-" table:"daily cost"`
|
||||
}
|
||||
|
||||
func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]codersdk.User, workspace codersdk.Workspace) workspaceListRow {
|
||||
|
@ -68,6 +69,7 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
|
|||
Outdated: workspace.Outdated,
|
||||
StartsAt: autostartDisplay,
|
||||
StopsAfter: autostopDisplay,
|
||||
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +80,19 @@ func (r *RootCmd) list() *clibase.Cmd {
|
|||
searchQuery string
|
||||
displayWorkspaces []workspaceListRow
|
||||
formatter = cliui.NewOutputFormatter(
|
||||
cliui.TableFormat([]workspaceListRow{}, nil),
|
||||
cliui.TableFormat(
|
||||
[]workspaceListRow{},
|
||||
[]string{
|
||||
"workspace",
|
||||
"template",
|
||||
"status",
|
||||
"healthy",
|
||||
"last built",
|
||||
"outdated",
|
||||
"starts at",
|
||||
"stops after",
|
||||
},
|
||||
),
|
||||
cliui.JSONFormat(),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -11,7 +11,7 @@ Aliases: ls
|
|||
-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, healthy, last built, outdated, starts at, stops
|
||||
after.
|
||||
after, daily cost.
|
||||
|
||||
-o, --output string (default: table)
|
||||
Output format. Available formats: table, json.
|
||||
|
|
|
@ -31,7 +31,7 @@ Specifies whether all workspaces will be listed or not.
|
|||
| 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, healthy, 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, daily cost.
|
||||
|
||||
### -o, --output
|
||||
|
||||
|
|
|
@ -404,7 +404,7 @@ func (p *Server) acquireJob(ctx context.Context) {
|
|||
runner.Options{
|
||||
Updater: p,
|
||||
QuotaCommitter: p,
|
||||
Logger: p.opts.Logger,
|
||||
Logger: p.opts.Logger.Named("runner"),
|
||||
Filesystem: p.opts.Filesystem,
|
||||
WorkDirectory: p.opts.WorkDirectory,
|
||||
Provisioner: provisioner,
|
||||
|
|
|
@ -964,6 +964,9 @@ func (r *Runner) buildWorkspace(ctx context.Context, stage string, req *sdkproto
|
|||
}
|
||||
|
||||
func (r *Runner) commitQuota(ctx context.Context, resources []*sdkproto.Resource) *proto.FailedJob {
|
||||
r.logger.Debug(ctx, "committing quota",
|
||||
slog.F("resources", resources),
|
||||
)
|
||||
cost := sumDailyCost(resources)
|
||||
if cost == 0 {
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue