forked from screwdriver-cd/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
168 lines (165 loc) · 4.11 KB
/
client.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package main
import (
"os"
"strings"
sd "github.com/screwdriver-cd/client/client"
"github.com/screwdriver-cd/client/commands"
filter "github.com/screwdriver-cd/client/commands/filters"
"github.com/urfave/cli"
)
// CreateApp creates an instance of the Screwdriver App
func CreateApp() *cli.App {
app := cli.NewApp()
app.Name = "Screwdriver Client"
app.Usage = "Continuous Delivery With Screwdriver"
app.Commands = []cli.Command{
{
Name: "pipelines",
Usage: "Screwdriver Pipelines",
Subcommands: []cli.Command{
{
Name: "list",
Usage: "List all pipelines",
Action: func(c *cli.Context) error {
resp, err := command.PipelinesList(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
command.FormattedPrint(resp)
return nil
},
ArgsUsage: "[pagination count] [pagination page]",
},
{
Name: "get",
Usage: "Get a pipeline by ID",
Action: func(c *cli.Context) error {
resp, err := command.PipelinesGetID(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
command.FormattedPrint(resp)
return nil
},
ArgsUsage: "<id>",
},
},
},
{
Name: "jobs",
Usage: "Screwdriver Jobs",
Subcommands: []cli.Command{
{
Name: "list",
Usage: "List all jobs",
Flags: []cli.Flag{
cli.StringFlag{
Name: "pipelineID, p",
Usage: "Only show jobs for specified pipeline",
},
},
Action: func(c *cli.Context) error {
resp, err := command.JobsList(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
pipelineIDFlag := c.String("pipelineID")
if strings.Compare(pipelineIDFlag, "") != 0 {
resp = filter.JobsFilterPipeline(resp, pipelineIDFlag)
}
command.FormattedPrint(resp)
return nil
},
ArgsUsage: "[pagination count] [pagination page]",
},
},
},
{
Name: "builds",
Usage: "Screwdriver Builds",
Subcommands: []cli.Command{
{
Name: "list",
Usage: "List all builds",
Flags: []cli.Flag{
cli.StringFlag{
Name: "jobID, j",
Usage: "Filter builds by jobID",
},
cli.StringFlag{
Name: "status, s",
Usage: "Only show builds of a certain status",
},
},
Action: func(c *cli.Context) error {
resp, err := command.BuildsList(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
jobIDFlag := c.String("jobID")
if strings.Compare(jobIDFlag, "") != 0 {
resp = filter.BuildsFilterJobs(resp, jobIDFlag)
}
buildStatusFlag := c.String("status")
if strings.Compare(buildStatusFlag, "") != 0 {
resp = filter.BuildsFilterStatus(resp, buildStatusFlag)
}
command.FormattedPrint(resp)
return nil
},
ArgsUsage: "[pagination count] [pagination page]",
},
{
Name: "get",
Usage: "Get a specific build",
ArgsUsage: "<id>",
Action: func(c *cli.Context) error {
resp, err := command.BuildsGetID(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
command.FormattedPrint(resp)
return nil
},
},
{
Name: "steps",
Usage: "Get a step record",
ArgsUsage: "<id> <stepName>",
Action: func(c *cli.Context) error {
resp, err := command.BuildsGetStep(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
command.FormattedPrint(resp)
return nil
},
},
{
Name: "steps-log",
Usage: "Get the logs for a step",
ArgsUsage: "<id> <stepName>",
Action: func(c *cli.Context) error {
resp, err := command.BuildsGetStepLogs(sd.Default, c)
if err != nil {
return cli.ShowSubcommandHelp(c)
}
command.FormattedPrint(resp)
return nil
},
Flags: []cli.Flag{
cli.IntFlag{
Name: "start, s",
Usage: "Start the logs for the step from a specific number",
},
},
},
},
},
}
return app
}
func main() {
app := CreateApp()
app.Run(os.Args)
}