Skip to content

Commit 958692d

Browse files
committed
feat: use --x- for --experimental- flags
1 parent a2dd051 commit 958692d

13 files changed

Lines changed: 502 additions & 183 deletions

File tree

cmd/osv-scanner/internal/helper/flags.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,57 @@ func BuildCommonScanFlags(defaultExtractors []string) []cli.Flag {
191191
Value: &allowedLicencesFlag{},
192192
},
193193
&cli.BoolFlag{
194-
Name: "experimental-flag-deprecated-packages",
194+
Name: "x-flag-deprecated-packages",
195195
Usage: "report if package versions are deprecated",
196196
},
197+
&cli.BoolFlag{
198+
Name: "experimental-flag-deprecated-packages",
199+
Usage: "[DEPRECATED] (use \"--x-flag-deprecated-packages\" instead) report if package versions are deprecated",
200+
Action: func(_ context.Context, _ *cli.Command, _ bool) error {
201+
cmdlogger.Warnf("Warning: --experimental-flag-deprecated-packages has been deprecated in favor of --x-flag-deprecated-packages")
202+
203+
return nil
204+
},
205+
},
197206
&cli.StringSliceFlag{
198207
Name: "experimental-plugins",
208+
Usage: "[DEPRECATED] (use \"--x-plugins\" instead) list of specific plugins and presets of plugins to use",
209+
Action: func(_ context.Context, _ *cli.Command, _ []string) error {
210+
cmdlogger.Warnf("Warning: --experimental-plugins has been deprecated in favor of --x-plugins")
211+
212+
return nil
213+
},
214+
Value: defaultExtractors,
215+
},
216+
&cli.StringSliceFlag{
217+
Name: "x-plugins",
199218
Usage: "list of specific plugins and presets of plugins to use",
200219
Value: defaultExtractors,
201220
},
202221
&cli.StringSliceFlag{
203222
Name: "experimental-disable-plugins",
223+
Usage: "[DEPRECATED] (use \"--x-disable-plugins\" instead) list of specific plugins and presets of plugins to not use",
224+
Action: func(_ context.Context, _ *cli.Command, _ []string) error {
225+
cmdlogger.Warnf("Warning: --experimental-disable-plugins has been deprecated in favor of --x-disable-plugins")
226+
227+
return nil
228+
},
229+
},
230+
&cli.StringSliceFlag{
231+
Name: "x-disable-plugins",
204232
Usage: "list of specific plugins and presets of plugins to not use",
205233
},
206234
&cli.BoolFlag{
207235
Name: "experimental-no-default-plugins",
236+
Usage: "[DEPRECATED] (use \"--x-no-default-plugins\" instead) disable default plugins, instead using only those enabled by --x-plugins",
237+
Action: func(_ context.Context, _ *cli.Command, _ bool) error {
238+
cmdlogger.Warnf("Warning: --experimental-no-default-plugins has been deprecated in favor of --x-no-default-plugins")
239+
240+
return nil
241+
},
242+
},
243+
&cli.BoolFlag{
244+
Name: "x-no-default-plugins",
208245
Usage: "disable default plugins, instead using only those enabled by --experimental-plugins",
209246
},
210247
}

cmd/osv-scanner/internal/helper/getters.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,22 @@ func GetCommonScannerActions(cmd *cli.Command, scanLicensesAllowlist []string) o
4949
}
5050
}
5151

52+
// FallbackToDeprecatedName returns the preferred cli flag name if set,
53+
// otherwise falling back to the deprecated name
54+
func FallbackToDeprecatedName(cmd *cli.Command, name, old string) string {
55+
if cmd.IsSet(name) {
56+
return name
57+
}
58+
59+
return old
60+
}
61+
5262
func GetExperimentalScannerActions(cmd *cli.Command, client *http.Client) osvscanner.ExperimentalScannerActions {
5363
return osvscanner.ExperimentalScannerActions{
54-
PluginsEnabled: cmd.StringSlice("experimental-plugins"),
55-
PluginsDisabled: cmd.StringSlice("experimental-disable-plugins"),
56-
PluginsNoDefaults: cmd.Bool("experimental-no-default-plugins"),
64+
PluginsEnabled: cmd.StringSlice(FallbackToDeprecatedName(cmd, "x-plugins", "experimental-plugins")),
65+
PluginsDisabled: cmd.StringSlice(FallbackToDeprecatedName(cmd, "x-disable-plugins", "experimental-disable-plugins")),
66+
PluginsNoDefaults: cmd.Bool(FallbackToDeprecatedName(cmd, "x-no-default-plugins", "experimental-no-default-plugins")),
5767
HTTPClient: client,
58-
FlagDeprecatedPackages: cmd.Bool("experimental-flag-deprecated-packages"),
68+
FlagDeprecatedPackages: cmd.Bool(FallbackToDeprecatedName(cmd, "x-flag-deprecated-packages", "experimental-flag-deprecated-packages")),
5969
}
6070
}

cmd/osv-scanner/scan/image/command_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestCommand_ExplicitExtractors_WithDefaults(t *testing.T) {
2323
Args: []string{
2424
"", "image",
2525
"--archive",
26-
"--experimental-plugins=sbom/spdx",
27-
"--experimental-plugins=sbom/cdx",
26+
"--x-plugins=sbom/spdx",
27+
"--x-plugins=sbom/cdx",
2828
"testdata/test-alpine-sbom.tar",
2929
},
3030
Exit: 1,
@@ -34,9 +34,9 @@ func TestCommand_ExplicitExtractors_WithDefaults(t *testing.T) {
3434
Args: []string{
3535
"", "image",
3636
"--archive",
37-
"--experimental-plugins=sbom/spdx",
38-
"--experimental-plugins=sbom/cdx",
39-
"--experimental-disable-plugins=sbom",
37+
"--x-plugins=sbom/spdx",
38+
"--x-plugins=sbom/cdx",
39+
"--x-disable-plugins=sbom",
4040
"testdata/test-alpine-sbom.tar",
4141
},
4242
Exit: 1,
@@ -46,8 +46,8 @@ func TestCommand_ExplicitExtractors_WithDefaults(t *testing.T) {
4646
Args: []string{
4747
"", "image",
4848
"--archive",
49-
"--experimental-plugins=sbom",
50-
"--experimental-disable-plugins=sbom",
49+
"--x-plugins=sbom",
50+
"--x-disable-plugins=sbom",
5151
"testdata/test-alpine-sbom.tar",
5252
},
5353
Exit: 1,
@@ -57,8 +57,8 @@ func TestCommand_ExplicitExtractors_WithDefaults(t *testing.T) {
5757
Args: []string{
5858
"", "image",
5959
"--archive",
60-
"--experimental-plugins=sbom/spdx,sbom/cdx",
61-
"--experimental-disable-plugins=sbom",
60+
"--x-plugins=sbom/spdx,sbom/cdx",
61+
"--x-disable-plugins=sbom",
6262
"testdata/test-alpine-sbom.tar",
6363
},
6464
Exit: 1,
@@ -88,9 +88,9 @@ func TestCommand_ExplicitExtractors_WithoutDefaults(t *testing.T) {
8888
Args: []string{
8989
"", "image",
9090
"--archive",
91-
"--experimental-plugins=sbom/spdx",
92-
"--experimental-plugins=sbom/cdx",
93-
"--experimental-no-default-plugins",
91+
"--x-plugins=sbom/spdx",
92+
"--x-plugins=sbom/cdx",
93+
"--x-no-default-plugins",
9494
"testdata/test-alpine-sbom.tar",
9595
},
9696
Exit: 1,
@@ -100,10 +100,10 @@ func TestCommand_ExplicitExtractors_WithoutDefaults(t *testing.T) {
100100
Args: []string{
101101
"", "image",
102102
"--archive",
103-
"--experimental-plugins=sbom/spdx",
104-
"--experimental-plugins=sbom/cdx",
105-
"--experimental-disable-plugins=sbom",
106-
"--experimental-no-default-plugins",
103+
"--x-plugins=sbom/spdx",
104+
"--x-plugins=sbom/cdx",
105+
"--x-disable-plugins=sbom",
106+
"--x-no-default-plugins",
107107
"testdata/test-alpine-sbom.tar",
108108
},
109109
Exit: 127,
@@ -113,9 +113,9 @@ func TestCommand_ExplicitExtractors_WithoutDefaults(t *testing.T) {
113113
Args: []string{
114114
"", "image",
115115
"--archive",
116-
"--experimental-plugins=sbom",
117-
"--experimental-disable-plugins=sbom",
118-
"--experimental-no-default-plugins",
116+
"--x-plugins=sbom",
117+
"--x-disable-plugins=sbom",
118+
"--x-no-default-plugins",
119119
"testdata/test-alpine-sbom.tar",
120120
},
121121
Exit: 127,
@@ -125,9 +125,9 @@ func TestCommand_ExplicitExtractors_WithoutDefaults(t *testing.T) {
125125
Args: []string{
126126
"", "image",
127127
"--archive",
128-
"--experimental-plugins=sbom/spdx,sbom/cdx",
129-
"--experimental-disable-plugins=sbom",
130-
"--experimental-no-default-plugins",
128+
"--x-plugins=sbom/spdx,sbom/cdx",
129+
"--x-disable-plugins=sbom",
130+
"--x-no-default-plugins",
131131
"testdata/test-alpine-sbom.tar",
132132
},
133133
Exit: 127,
@@ -193,7 +193,7 @@ func TestCommand_Docker(t *testing.T) {
193193
// since we've requested the os/apk extractor disabled, and there's nothing else
194194
// in the image that we support extracting
195195
Name: "real_alpine_image_without_apk_extractor_enabled",
196-
Args: []string{"", "image", "--experimental-disable-plugins=os/apk", "alpine:3.18.9"},
196+
Args: []string{"", "image", "--x-disable-plugins=os/apk", "alpine:3.18.9"},
197197
Exit: 128,
198198
},
199199
}
@@ -325,8 +325,8 @@ func TestCommand_OCIImage(t *testing.T) {
325325
Name: "scanning_insecure_alpine_image_with_specific_detector_enabled",
326326
Args: []string{
327327
"", "image",
328-
"--experimental-plugins", "os/apk",
329-
"--experimental-plugins", "weakcredentials/etcshadow",
328+
"--x-plugins", "os/apk",
329+
"--x-plugins", "weakcredentials/etcshadow",
330330
"--archive", "./testdata/test-alpine-etcshadow.tar",
331331
},
332332
Exit: 1,
@@ -335,9 +335,9 @@ func TestCommand_OCIImage(t *testing.T) {
335335
Name: "scanning_insecure_alpine_image_with_specific_detector_disabled",
336336
Args: []string{
337337
"", "image",
338-
"--experimental-plugins", "os/apk",
339-
"--experimental-plugins", "weakcreds",
340-
"--experimental-disable-plugins", "weakcredentials/etcshadow",
338+
"--x-plugins", "os/apk",
339+
"--x-plugins", "weakcreds",
340+
"--x-disable-plugins", "weakcredentials/etcshadow",
341341
"--archive", "./testdata/test-alpine-etcshadow.tar",
342342
},
343343
Exit: 1,
@@ -346,8 +346,8 @@ func TestCommand_OCIImage(t *testing.T) {
346346
Name: "scanning_insecure_alpine_image_with_detector_preset",
347347
Args: []string{
348348
"", "image",
349-
"--experimental-plugins", "os/apk",
350-
"--experimental-plugins", "weakcreds",
349+
"--x-plugins", "os/apk",
350+
"--x-plugins", "weakcreds",
351351
"--archive", "./testdata/test-alpine-etcshadow.tar",
352352
},
353353
Exit: 1,
@@ -445,8 +445,8 @@ func TestCommand_OCIImage_JSONFormat(t *testing.T) {
445445
Name: "scanning_insecure_alpine_image_with_specific_detector_enabled",
446446
Args: []string{
447447
"", "image", "--format=json",
448-
"--experimental-plugins", "os/apk",
449-
"--experimental-plugins", "weakcredentials/etcshadow",
448+
"--x-plugins", "os/apk",
449+
"--x-plugins", "weakcredentials/etcshadow",
450450
"--archive", "./testdata/test-alpine-etcshadow.tar",
451451
},
452452
Exit: 1,
@@ -461,8 +461,8 @@ func TestCommand_OCIImage_JSONFormat(t *testing.T) {
461461
Name: "scanning_insecure_alpine_image_with_detector_preset",
462462
Args: []string{
463463
"", "image", "--format=json",
464-
"--experimental-plugins", "os/apk",
465-
"--experimental-plugins", "weakcreds",
464+
"--x-plugins", "os/apk",
465+
"--x-plugins", "weakcreds",
466466
"--archive", "./testdata/test-alpine-etcshadow.tar",
467467
},
468468
Exit: 1,
@@ -477,7 +477,7 @@ func TestCommand_OCIImage_JSONFormat(t *testing.T) {
477477
Name: "scanning_image_with_deprecated_packages",
478478
Args: []string{
479479
"", "image", "--format=json",
480-
"--experimental-flag-deprecated-packages",
480+
"--x-flag-deprecated-packages",
481481
"--archive", "./testdata/test-image-with-deprecated.tar",
482482
},
483483
Exit: 1,

0 commit comments

Comments
 (0)