Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4c4ebc

Browse files
committed
Fix workspace list
1 parent71e4544 commita4c4ebc

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

‎cli/workspacedelete.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,7 @@ func workspaceDelete() *cobra.Command {
3232
iferr!=nil {
3333
returnerr
3434
}
35-
err=cliui.ProvisionerJob(cmd.Context(),cmd.OutOrStdout(), cliui.ProvisionerJobOptions{
36-
Fetch:func() (codersdk.ProvisionerJob,error) {
37-
build,err:=client.WorkspaceBuild(cmd.Context(),build.ID)
38-
returnbuild.Job,err
39-
},
40-
Cancel:func()error {
41-
returnclient.CancelWorkspaceBuild(cmd.Context(),build.ID)
42-
},
43-
Logs:func() (<-chan codersdk.ProvisionerJobLog,error) {
44-
returnclient.WorkspaceBuildLogsAfter(cmd.Context(),build.ID,before)
45-
},
46-
})
47-
returnerr
35+
returncliui.WorkspaceBuild(cmd.Context(),cmd.OutOrStdout(),client,build.ID,before)
4836
},
4937
}
5038
}

‎cli/workspacelist.go

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package cli
22

33
import (
44
"fmt"
5-
"text/tabwriter"
6-
"time"
75

8-
"github.com/fatih/color"
6+
"github.com/jedib0t/go-pretty/v6/table"
97
"github.com/spf13/cobra"
108

119
"github.com/coder/coder/cli/cliui"
10+
"github.com/coder/coder/coderd/database"
1211
"github.com/coder/coder/codersdk"
1312
)
1413

@@ -21,7 +20,6 @@ func workspaceList() *cobra.Command {
2120
iferr!=nil {
2221
returnerr
2322
}
24-
start:=time.Now()
2523
workspaces,err:=client.WorkspacesByUser(cmd.Context(),codersdk.Me)
2624
iferr!=nil {
2725
returnerr
@@ -34,27 +32,47 @@ func workspaceList() *cobra.Command {
3432
returnnil
3533
}
3634

37-
_,_=fmt.Fprintf(cmd.OutOrStdout(),"%s Workspaces found %s\n\n",
38-
caret,
39-
color.HiBlackString("[%dms]",
40-
time.Since(start).Milliseconds()))
41-
42-
writer:=tabwriter.NewWriter(cmd.OutOrStdout(),0,0,4,' ',0)
43-
_,_=fmt.Fprintf(writer,"%s\t%s\t%s\t%s\t%s\n",
44-
color.HiBlackString("Workspace"),
45-
color.HiBlackString("Template"),
46-
color.HiBlackString("Status"),
47-
color.HiBlackString("Last Built"),
48-
color.HiBlackString("Outdated"))
35+
tableWriter:=table.NewWriter()
36+
tableWriter.SetStyle(table.StyleLight)
37+
tableWriter.Style().Options.SeparateColumns=false
38+
tableWriter.AppendHeader(table.Row{"Workspace","Template","Status","Last Built","Outdated"})
39+
4940
for_,workspace:=rangeworkspaces {
50-
_,_=fmt.Fprintf(writer,"%s\t%s\t%s\t%s\t%+v\n",
51-
color.New(color.FgHiCyan).Sprint(workspace.Name),
52-
color.WhiteString(workspace.TemplateName),
53-
color.WhiteString(string(workspace.LatestBuild.Transition)),
54-
color.WhiteString(workspace.LatestBuild.Job.CompletedAt.Format("January 2, 2006")),
55-
workspace.Outdated)
41+
status:=""
42+
inProgress:=false
43+
ifworkspace.LatestBuild.Job.Status==codersdk.ProvisionerJobRunning||
44+
workspace.LatestBuild.Job.Status==codersdk.ProvisionerJobCanceling {
45+
inProgress=true
46+
}
47+
48+
switchworkspace.LatestBuild.Transition {
49+
casedatabase.WorkspaceTransitionStart:
50+
status="start"
51+
ifinProgress {
52+
status="starting"
53+
}
54+
casedatabase.WorkspaceTransitionStop:
55+
status="stop"
56+
ifinProgress {
57+
status="stopping"
58+
}
59+
casedatabase.WorkspaceTransitionDelete:
60+
status="delete"
61+
ifinProgress {
62+
status="deleting"
63+
}
64+
}
65+
66+
tableWriter.AppendRow(table.Row{
67+
cliui.Styles.Bold.Render(workspace.Name),
68+
workspace.TemplateName,
69+
status,
70+
workspace.LatestBuild.Job.CreatedAt.Format("January 2, 2006"),
71+
workspace.Outdated,
72+
})
5673
}
57-
returnwriter.Flush()
74+
_,err=fmt.Fprintf(cmd.OutOrStdout(),tableWriter.Render())
75+
returnerr
5876
},
5977
}
6078
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp