forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.go
57 lines (45 loc) · 1.23 KB
/
watch.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
package commands
import (
"fmt"
"os"
"strconv"
"github.com/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/fly/eventstream"
"github.com/concourse/fly/rc"
)
type WatchCommand struct {
Job flaghelpers.JobFlag `short:"j" long:"job" value-name:"PIPELINE/JOB" description:"Watches builds of the given job"`
Build string `short:"b" long:"build" description:"Watches a specific build"`
}
func (command *WatchCommand) Execute(args []string) error {
target, err := rc.LoadTarget(Fly.Target)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
var buildId int
client := target.Client()
if command.Job.JobName != "" || command.Build == "" {
build, err := GetBuild(client, target.Team(), command.Job.JobName, command.Build, command.Job.PipelineName)
if err != nil {
return err
}
buildId = build.ID
} else if command.Build != "" {
buildId, err = strconv.Atoi(command.Build)
if err != nil {
return err
}
}
eventSource, err := client.BuildEvents(fmt.Sprintf("%d", buildId))
if err != nil {
return err
}
exitCode := eventstream.Render(os.Stdout, eventSource)
eventSource.Close()
os.Exit(exitCode)
return nil
}