This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
flags.go
341 lines (320 loc) · 11 KB
/
flags.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Copyright (c) 2018 SUSE LLC. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"log"
"os/user"
"github.com/codegangsta/cli"
)
// A pointer to the current context.
var currentContext *cli.Context
// Returns the version string
func version() string {
const (
major = 2
minor = 0
patch = 0
)
return fmt.Sprintf("%v.%v.%v", major, minor, patch)
}
func defaultCommitAuthor() string {
current, err := user.Current()
if err != nil {
log.Printf("Cannot determine current user: %s", err)
return ""
}
if current.Name != "" {
return current.Name
}
return current.Username
}
// It returns an application with all the flags and subcommands already in
// place.
func newApp() *cli.App {
app := cli.NewApp()
app.Name = "zypper-docker"
app.Usage = "Patching Docker images safely"
app.Version = version()
app.CommandNotFound = func(context *cli.Context, cmd string) {
fmt.Printf("Incorrect usage: command '%v' does not exist.\n\n", cmd)
cli.ShowAppHelp(context)
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "no-gpg-checks",
Usage: "Ignore GPG check failures and continue",
},
cli.BoolFlag{
Name: "gpg-auto-import-keys",
Usage: "If new repository signing key is found, do not ask what to do; trust and import it automatically",
},
cli.BoolFlag{
Name: "f, force",
Usage: "Ignore all the local caches",
},
cli.BoolFlag{
Name: "d, debug",
Usage: "Show all the logged messages on stdout",
},
cli.StringSliceFlag{
Name: "add-host",
Usage: "Add a custom host-to-IP mapping (host:ip)",
},
}
app.Commands = []cli.Command{
{
Name: "images",
Usage: "List all the images based on either OpenSUSE or SLES",
Action: getCmd("images", imagesCmd),
ArgsUsage: " ",
},
{
Name: "list-updates",
Aliases: []string{"lu"},
Usage: "List all the available updates",
Action: getCmd("list-updates", listUpdatesCmd),
UsageText: `zypper-docker list-updates <image>
zypper-docker lu <image>
Where <image> is the name of the openSUSE/SUSE Linux Enterprise image to use.
If the tag has not been provided, then "latest" is the one that will be used.`,
},
{
Name: "list-updates-container",
Aliases: []string{"luc"},
Usage: "List all the available updates for the given container",
Action: getCmd("list-updates-container", listUpdatesContainerCmd),
UsageText: `zypper-docker list-updates-container <container-id>
zypper-docker luc <container-id>
Where <container-id> is either the container ID or the name of the container
to be used.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "base",
Usage: "Analyze the base image of the container for updates.",
},
},
},
{
Name: "update",
Aliases: []string{"up"},
Usage: "Install the available updates",
Action: getCmd("update", updateCmd),
UsageText: `zypper-docker update [command options] <image> <new-image>
zypper-docker up [command options] <image> <new-image>
Where <image> is the name of the openSUSE/SUSE Linux Enterprise image to
update. Since zypper-docker does not overwrite images, <new-image> is the name
of the image that will be created on this operation. This new image will be the
same as the old one plus the applied updates.
If the tag has not been provided on either <image> or <new-image>, then
"latest" is the one that will be used.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "l, auto-agree-with-licenses",
Usage: "Automatically say yes to third party license confirmation prompt. By using this option, you choose to agree with licenses of all third-party software this command will install.",
},
cli.BoolFlag{
Name: "no-recommends",
Usage: "By default, zypper installs also packages recommended by the requested ones. This option causes the recommended packages to be ignored and only the required ones to be installed.",
},
cli.BoolFlag{
Name: "replacefiles",
Usage: "Install the packages even if they replace files from other, already installed, packages. Default is to treat file conflicts as an error.",
},
cli.StringFlag{
Name: "author",
Value: defaultCommitAuthor(),
Usage: "Commit author to associate with the new layer (e.g., \"John Doe <[email protected]>\")",
},
cli.StringFlag{
Name: "message",
Value: "[zypper-docker] update",
Usage: "Commit message to associated with the new layer",
},
},
},
{
Name: "list-patches",
Aliases: []string{"lp"},
Usage: "List all the available patches",
Action: getCmd("list-patches", listPatchesCmd),
UsageText: `zypper-docker list-patches [command options] <image>
zypper-docker lp [command options] <image>
Where <image> is the name of the openSUSE/SUSE Linux Enterprise image to use.
If the tag has not been provided, then "latest" is the one that will be used.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bugzilla",
Value: "",
Usage: "List available needed patches for all Bugzilla issues, or issues whose number matches the given string (--bugzilla=#).",
},
cli.StringFlag{
Name: "cve",
Value: "",
Usage: "List available needed patches for all CVE issues, or issues whose number matches the given string (--cve=#).",
},
cli.StringFlag{
Name: "date",
Value: "",
Usage: "List patches issued up to, but not including, the specified date (YYYY-MM-DD).",
},
cli.StringFlag{
Name: "issues",
Value: "",
Usage: "Look for issues whose number, summary, or description matches the specified string (--issue=string).",
},
cli.StringFlag{
Name: "g, category",
Value: "",
Usage: "List only patches with this category.",
},
cli.StringFlag{
Name: "severity",
Value: "",
Usage: "List only patches with this severity.",
},
},
},
{
Name: "list-patches-container",
Aliases: []string{"lpc"},
Usage: "List all the available patches for the given container",
Action: getCmd("list-patches-container", listPatchesContainerCmd),
UsageText: `zypper-docker list-patches-container [command options] <container-id>
zypper-docker lpc [command options] <container-id>
Where <container-id> is either the container ID or the name of the container
to be used.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "base",
Usage: "Analyse the base image of the container for patches.",
},
cli.StringFlag{
Name: "b, bugzilla",
Value: "",
Usage: "List available needed patches for all Bugzilla issues, or issues whose number matches the given string (--bugzilla=#).",
},
cli.StringFlag{
Name: "cve",
Value: "",
Usage: "List available needed patches for all CVE issues, or issues whose number matches the given string (--cve=#).",
},
cli.StringFlag{
Name: "date",
Value: "",
Usage: "List patches issued up to, but not including, the specified date (YYYY-MM-DD).",
},
cli.StringFlag{
Name: "issues",
Value: "",
Usage: "Look for issues whose number, summary, or description matches the specified string (--issue=string).",
},
cli.StringFlag{
Name: "g, category",
Value: "",
Usage: "List only patches with this category.",
},
},
},
{
Name: "patch",
Usage: "Install the available patches",
Action: getCmd("patch", patchCmd),
ArgsUsage: `<image> <new-image>
Where <image> is the name of the openSUSE/SUSE Linux Enterprise image to
patch. Since zypper-docker does not overwrite images, <new-image> is the name
of the image that will be created on this operation. This new image will be the
same as the old one plus the applied patches.
If the tag has not been provided on either <image> or <new-image>, then
"latest" is the one that will be used.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bugzilla",
Value: "",
Usage: "Install available needed patches for all Bugzilla issues, or issues whose number matches the given string (--bugzilla=#).",
},
cli.StringFlag{
Name: "cve",
Value: "",
Usage: "Install available needed patches for all CVE issues, or issues whose number matches the given string (--cve=#).",
},
cli.StringFlag{
Name: "date",
Value: "",
Usage: "Install patches issued up to, but not including, the specified date (YYYY-MM-DD).",
},
cli.StringFlag{
Name: "g, category",
Value: "",
Usage: "Install only patches with this category.",
},
cli.BoolFlag{
Name: "l, auto-agree-with-licenses",
Usage: "Automatically say yes to third party license confirmation prompt. By using this option, you choose to agree with licenses of all third-party software this command will install.",
},
cli.BoolFlag{
Name: "no-recommends",
Usage: "By default, zypper installs also packages recommended by the requested ones. This option causes the recommended packages to be ignored and only the required ones to be installed.",
},
cli.BoolFlag{
Name: "replacefiles",
Usage: "Install the packages even if they replace files from other, already installed, packages. Default is to treat file conflicts as an error.",
},
cli.StringFlag{
Name: "author",
Value: defaultCommitAuthor(),
Usage: "Commit author to associate with the new layer (e.g., \"John Doe <[email protected]>\")",
},
cli.StringFlag{
Name: "message",
Value: "[zypper-docker] patch",
Usage: "Commit message to associated with the new layer",
},
},
},
{
Name: "patch-check",
Aliases: []string{"pchk"},
Usage: "Check for patches",
Action: getCmd("patch-check", patchCheckCmd),
UsageText: `zypper-docker patch-check <image>
zypper-docker pchk <image>
Where <image> is the name of the openSUSE/SUSE Linux Enterprise image to use.
If the tag has not been provided, then "latest" is the one that will be used.`,
},
{
Name: "patch-check-container",
Aliases: []string{"pchkc"},
Usage: "Check for patches available for the given container",
Action: getCmd("patch-check-container", patchCheckContainerCmd),
UsageText: `zypper-docker patch-check-container <container-id>
zypper-docker pchkc <container-id>
Where <container-id> is either the container ID or the name of the container
to be used.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "base",
Usage: "Execute a patch-check on the base image of the container.",
},
},
},
{
Name: "ps",
Usage: "List all the containers that are outdated",
Action: getCmd("ps", psCmd),
ArgsUsage: " ",
},
}
return app
}