forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locks.go
43 lines (34 loc) · 897 Bytes
/
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
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: []string{"Type", "Resource", "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.NewValueTime(l.ExpiresAt),
})
}
c.ui.PrintTable(table)
return nil
}