-
Notifications
You must be signed in to change notification settings - Fork 161
/
tasks.go
71 lines (60 loc) · 1.65 KB
/
tasks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cmd
import (
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type TasksCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewTasksCmd(ui boshui.UI, director boshdir.Director) TasksCmd {
return TasksCmd{ui: ui, director: director}
}
func (c TasksCmd) Run(opts TasksOpts) error {
filter := boshdir.TasksFilter{
All: opts.All,
Deployment: opts.Deployment,
}
if opts.Recent != nil {
return c.printTable(c.director.RecentTasks(*opts.Recent, filter))
}
filter.All = true
return c.printTable(c.director.CurrentTasks(filter))
}
func (c TasksCmd) printTable(tasks []boshdir.Task, err error) error {
if err != nil {
return err
}
table := boshtbl.Table{
Content: "tasks",
Header: []boshtbl.Header{
boshtbl.NewHeader("ID"),
boshtbl.NewHeader("State"),
boshtbl.NewHeader("Started At"),
boshtbl.NewHeader("Last Activity At"),
boshtbl.NewHeader("User"),
boshtbl.NewHeader("Deployment"),
boshtbl.NewHeader("Description"),
boshtbl.NewHeader("Result"),
},
SortBy: []boshtbl.ColumnSort{{Column: 0}},
}
for _, t := range tasks {
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueInt(t.ID()),
boshtbl.ValueFmt{
V: boshtbl.NewValueString(t.State()),
Error: t.IsError(),
},
boshtbl.NewValueTime(t.StartedAt()),
boshtbl.NewValueTime(t.LastActivityAt()),
boshtbl.NewValueString(t.User()),
boshtbl.NewValueString(t.DeploymentName()),
boshtbl.NewValueString(t.Description()),
boshtbl.NewValueString(t.Result()),
})
}
c.ui.PrintTable(table)
return nil
}