-
Notifications
You must be signed in to change notification settings - Fork 162
/
task.go
69 lines (58 loc) · 1.32 KB
/
task.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
package cmd
import (
"errors"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshuit "github.com/cloudfoundry/bosh-cli/ui/task"
)
type TaskCmd struct {
eventsTaskReporter boshuit.Reporter
plainTaskReporter boshuit.Reporter
director boshdir.Director
}
func NewTaskCmd(
eventsTaskReporter boshuit.Reporter,
plainTaskReporter boshuit.Reporter,
director boshdir.Director,
) TaskCmd {
return TaskCmd{
eventsTaskReporter: eventsTaskReporter,
plainTaskReporter: plainTaskReporter,
director: director,
}
}
func (c TaskCmd) Run(opts TaskOpts) error {
var task boshdir.Task
var err error
if opts.Args.ID == 0 {
filter := boshdir.TasksFilter{
All: opts.All,
Deployment: opts.Deployment,
}
tasks, err := c.director.CurrentTasks(filter)
if err != nil {
return err
}
if len(tasks) == 0 {
return errors.New("No task found")
}
task = tasks[0]
} else {
task, err = c.director.FindTask(opts.Args.ID)
if err != nil {
return err
}
}
switch {
case opts.Event:
err = task.EventOutput(c.plainTaskReporter)
case opts.CPI:
err = task.CPIOutput(c.plainTaskReporter)
case opts.Debug:
err = task.DebugOutput(c.plainTaskReporter)
case opts.Result:
err = task.ResultOutput(c.plainTaskReporter)
default:
err = task.EventOutput(c.eventsTaskReporter)
}
return err
}