-
Notifications
You must be signed in to change notification settings - Fork 162
/
locks.go
49 lines (40 loc) · 1.02 KB
/
locks.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
package cmd
import (
"strings"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type LocksCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewLocksCmd(ui boshui.UI, director boshdir.Director) LocksCmd {
return LocksCmd{ui: ui, director: director}
}
func (c LocksCmd) Run() error {
locks, err := c.director.Locks()
if err != nil {
return err
}
table := boshtbl.Table{
Content: "locks",
Header: []boshtbl.Header{
boshtbl.NewHeader("Type"),
boshtbl.NewHeader("Resource"),
boshtbl.NewHeader("Task ID"),
boshtbl.NewHeader("Expires at"),
},
SortBy: []boshtbl.ColumnSort{{Column: 2, Asc: true}},
}
for _, l := range locks {
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString(l.Type),
boshtbl.NewValueString(strings.Join(l.Resource, ":")),
boshtbl.NewValueString(l.TaskID),
boshtbl.NewValueTime(l.ExpiresAt),
})
}
c.ui.PrintTable(table)
return nil
}