@@ -2,13 +2,12 @@ package cli
2
2
3
3
import (
4
4
"fmt"
5
- "text/tabwriter"
6
- "time"
7
5
8
- "github.com/fatih/color "
6
+ "github.com/jedib0t/go-pretty/v6/table "
9
7
"github.com/spf13/cobra"
10
8
11
9
"github.com/coder/coder/cli/cliui"
10
+ "github.com/coder/coder/coderd/database"
12
11
"github.com/coder/coder/codersdk"
13
12
)
14
13
@@ -21,7 +20,6 @@ func workspaceList() *cobra.Command {
21
20
if err != nil {
22
21
return err
23
22
}
24
- start := time .Now ()
25
23
workspaces , err := client .WorkspacesByUser (cmd .Context (), codersdk .Me )
26
24
if err != nil {
27
25
return err
@@ -34,27 +32,47 @@ func workspaceList() *cobra.Command {
34
32
return nil
35
33
}
36
34
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
+
49
40
for _ , workspace := range workspaces {
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
+ if workspace .LatestBuild .Job .Status == codersdk .ProvisionerJobRunning ||
44
+ workspace .LatestBuild .Job .Status == codersdk .ProvisionerJobCanceling {
45
+ inProgress = true
46
+ }
47
+
48
+ switch workspace .LatestBuild .Transition {
49
+ case database .WorkspaceTransitionStart :
50
+ status = "start"
51
+ if inProgress {
52
+ status = "starting"
53
+ }
54
+ case database .WorkspaceTransitionStop :
55
+ status = "stop"
56
+ if inProgress {
57
+ status = "stopping"
58
+ }
59
+ case database .WorkspaceTransitionDelete :
60
+ status = "delete"
61
+ if inProgress {
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
+ })
56
73
}
57
- return writer .Flush ()
74
+ _ , err = fmt .Fprintf (cmd .OutOrStdout (), tableWriter .Render ())
75
+ return err
58
76
},
59
77
}
60
78
}
0 commit comments