This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
62 lines (51 loc) · 1.45 KB
/
events.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
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 EventsCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewEventsCmd(ui boshui.UI, director boshdir.Director) EventsCmd {
return EventsCmd{ui: ui, director: director}
}
func (c EventsCmd) Run(opts EventsOpts) error {
filter := boshdir.EventsFilter{
BeforeID: opts.BeforeID,
Before: opts.Before,
After: opts.After,
Deployment: opts.Deployment,
Task: opts.Task,
Instance: opts.Instance,
}
events, err := c.director.Events(filter)
if err != nil {
return err
}
table := boshtbl.Table{
Content: "events",
Header: []string{"ID", "Time", "User", "Action", "Object Type", "Object ID", "Task ID", "Deployment", "Instance", "Context"},
}
for _, e := range events {
id := e.ID()
if e.ParentID() != "" {
id += " <- " + e.ParentID()
}
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString(id),
boshtbl.NewValueTime(e.Timestamp()),
boshtbl.NewValueString(e.User()),
boshtbl.NewValueString(e.Action()),
boshtbl.NewValueString(e.ObjectType()),
boshtbl.NewValueString(e.ObjectName()),
boshtbl.NewValueString(e.TaskID()),
boshtbl.NewValueString(e.DeploymentName()),
boshtbl.NewValueString(e.Instance()),
boshtbl.NewValueInterface(e.Context()),
})
}
c.ui.PrintTable(table)
return nil
}