-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
169 lines (164 loc) · 4.29 KB
/
cmd.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
169
package cmd
import (
"errors"
"os"
"github.com/Sirupsen/logrus"
"github.com/spinnaker/roer"
"github.com/spinnaker/roer/spinnaker"
"github.com/urfave/cli"
)
// NewRoer returns a new instance of the OSS roer application
func NewRoer(version string, clientConfig spinnaker.ClientConfig) *cli.App {
cli.VersionFlag.Name = "version"
cli.HelpFlag.Name = "help"
cli.HelpFlag.Hidden = true
app := cli.NewApp()
app.Name = "roer"
app.Usage = "Spinnaker CLI"
app.Version = version
app.Commands = []cli.Command{
{
Name: "pipeline",
Usage: "pipeline tasks",
Subcommands: []cli.Command{
{
Name: "save",
Usage: "save a pipeline configuration",
ArgsUsage: "[configuration.yml]",
Before: func(cc *cli.Context) error {
if cc.NArg() != 1 {
return errors.New("path to configuration file is required")
}
return nil
},
Action: roer.PipelineSaveAction(clientConfig),
},
},
},
{
Name: "pipeline-template",
Usage: "pipeline template tasks",
Subcommands: []cli.Command{
{
Name: "publish",
Usage: "publish a pipeline template, will create or update a template",
ArgsUsage: "[template.yml]",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "update, u",
Usage: "DEPRECATED: update the given pipeline, the default action always creates or updates",
},
cli.BoolFlag{
Name: "skipPlan, s",
Usage: "skip the plan dependent pipelines safety feature",
},
},
Before: func(cc *cli.Context) error {
if cc.NArg() != 1 {
return errors.New("path to template file is required")
}
return nil
},
Action: roer.PipelineTemplatePublishAction(clientConfig),
},
{
Name: "plan",
Usage: "validate a pipeline template and or plan a configuration",
Description: `
Given a pipeline template configuration, a plan operation
will be run, with either the errors being returned or the
final pipeline JSON that would be executed.
`,
ArgsUsage: "[configuration.yml]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "template, t",
Usage: "local template to inline while planning",
},
},
Before: func(cc *cli.Context) error {
if cc.NArg() != 1 {
return errors.New("path to configuration file is required")
}
return nil
},
Action: roer.PipelineTemplatePlanAction(clientConfig),
},
{
Name: "convert",
Usage: "converts an existing, non-templated pipeline config into a scaffolded template",
ArgsUsage: "[appName] [pipelineName]",
Before: func(cc *cli.Context) error {
if cc.NArg() != 2 {
return errors.New("appName and pipelineName args are required")
}
return nil
},
Action: roer.PipelineTemplateConvertAction(clientConfig),
},
{
Name: "delete",
Usage: "deletes a pipeline template",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id",
Usage: "id of the template to delete",
},
},
Before: func(cc *cli.Context) error {
if cc.NArg() != 1 {
return errors.New("id is required")
}
return nil
},
Action: roer.PipelineTemplateDeleteAction(clientConfig),
},
// {
// Name: "run",
// Usage: "run a pipeline",
// ArgsUsage: "[configuration.yml]",
// Before: func(cc *cli.Context) error {
// if cc.NArg() != 1 {
// return errors.New("path to configuration file is required")
// }
// return nil
// },
// Action: roer.PipelineTemplateRunAction(clientConfig),
// },
},
},
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose, v",
Usage: "show debug messages",
},
cli.StringFlag{
Name: "certPath, c",
Usage: "HTTPS x509 cert path",
},
cli.StringFlag{
Name: "keyPath, k",
Usage: "HTTPS x509 key path",
},
cli.StringFlag{
Name: "apiSession, as",
Usage: "your active api session",
},
}
app.Before = func(cc *cli.Context) error {
if cc.GlobalBool("verbose") {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
return app
}
func validateFileExists(name, f string) {
if _, err := os.Stat(f); os.IsNotExist(err) {
logrus.WithFields(logrus.Fields{
"name": name,
"file": f,
}).Error("file does not exist")
}
}