Skip to content

Commit 33b40fe

Browse files
committed
feat: improve locality of defaults
1 parent a38777e commit 33b40fe

File tree

2 files changed

+34
-43
lines changed

2 files changed

+34
-43
lines changed

cve_bin_tool/cli.py

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ def main(argv=None):
9393
action="store",
9494
choices=["api", "json"],
9595
help="choose method for getting CVE lists from NVD",
96+
default="api",
9697
)
9798
nvd_database_group.add_argument(
9899
"-u",
99100
"--update",
100101
action="store",
101102
choices=["now", "daily", "never", "latest"],
102103
help="update schedule for NVD database (default: daily)",
104+
default="daily",
103105
)
104106
nvd_database_group.add_argument(
105107
"--nvd-api-key",
@@ -110,7 +112,7 @@ def main(argv=None):
110112

111113
input_group = parser.add_argument_group("Input")
112114
input_group.add_argument(
113-
"directory", help="directory to scan", nargs="?", default=None
115+
"directory", help="directory to scan", nargs="?", default=""
114116
)
115117
input_group.add_argument(
116118
"-i",
@@ -136,11 +138,16 @@ def main(argv=None):
136138
"--sbom-file",
137139
action="store",
138140
help="provide sbom filename",
141+
default="",
139142
)
140143

141144
output_group = parser.add_argument_group("Output")
142145
output_group.add_argument(
143-
"-q", "--quiet", action="store_true", help="suppress output"
146+
"-q",
147+
"--quiet",
148+
action="store_true",
149+
help="suppress output",
150+
default=False,
144151
)
145152
output_group.add_argument(
146153
"-l",
@@ -149,42 +156,49 @@ def main(argv=None):
149156
dest="log_level",
150157
action="store",
151158
choices=["debug", "info", "warning", "error", "critical"],
159+
default="info",
152160
)
153161
output_group.add_argument(
154162
"-o",
155163
"--output-file",
156164
action="store",
157165
help="provide output filename (default: output to stdout)",
166+
default="",
158167
)
159168
output_group.add_argument(
160169
"--html-theme",
161170
action="store",
162171
help="provide custom theme directory for HTML Report",
172+
default="",
163173
)
164174
output_group.add_argument(
165175
"-f",
166176
"--format",
167177
action="store",
168178
choices=["csv", "json", "console", "html", "pdf"],
169179
help="update output format (default: console)",
180+
default="console",
170181
)
171182
output_group.add_argument(
172183
"-c",
173184
"--cvss",
174185
action="store",
175186
help="minimum CVSS score (as integer in range 0 to 10) to report (default: 0)",
187+
default=0,
176188
)
177189
output_group.add_argument(
178190
"-S",
179191
"--severity",
180192
action="store",
181193
choices=["low", "medium", "high", "critical"],
182194
help="minimum CVE severity to report (default: low)",
195+
default="low",
183196
)
184197
output_group.add_argument(
185198
"--report",
186199
action="store_true",
187200
help="Produces a report even if there are no CVE for the respective output format",
201+
default=False,
188202
)
189203
output_group.add_argument(
190204
"-A",
@@ -195,6 +209,7 @@ def main(argv=None):
195209
choices=get_available_fix_supported_distros(),
196210
metavar="<distro_name>-<distro_version_name>",
197211
help="Lists available fixes of the package from Linux distribution",
212+
default="",
198213
)
199214
output_group.add_argument(
200215
"-b",
@@ -205,6 +220,7 @@ def main(argv=None):
205220
choices=get_backport_supported_distros(),
206221
metavar="<distro_name>-<distro_version_name>",
207222
help="Lists backported fixes if available from Linux distribution",
223+
default="",
208224
)
209225
output_group.add_argument(
210226
"--affected-versions",
@@ -218,18 +234,20 @@ def main(argv=None):
218234
"--exclude",
219235
action=StringToListAction,
220236
help="Comma separated Exclude directory path",
221-
default=None,
237+
default=[],
222238
)
223239
parser.add_argument("-V", "--version", action="version", version=VERSION)
224240
parser.add_argument(
225241
"--disable-version-check",
226242
action="store_true",
227243
help="skips checking for a new version",
244+
default=False,
228245
)
229246
parser.add_argument(
230247
"--offline",
231248
action="store_true",
232249
help="operate in offline mode",
250+
default=False,
233251
)
234252

235253
merge_report_group = parser.add_argument_group(
@@ -241,24 +259,28 @@ def main(argv=None):
241259
nargs="?",
242260
const=True,
243261
help="save output as intermediate report in json format",
262+
default=False,
244263
)
245264
merge_report_group.add_argument(
246265
"-t",
247266
"--tag",
248267
action="store",
249268
help="add a unique tag to differentiate between multiple intermediate reports",
269+
default="",
250270
)
251271
merge_report_group.add_argument(
252272
"-m",
253273
"--merge",
254274
action=StringToListAction,
255275
help="comma separated intermediate reports path for merging",
276+
default=None,
256277
)
257278
merge_report_group.add_argument(
258279
"-F",
259280
"--filter",
260281
action=StringToListAction,
261282
help="comma separated tag string for filtering intermediate reports",
283+
default=[],
262284
)
263285

264286
checker_group = parser.add_argument_group("Checkers")
@@ -269,6 +291,7 @@ def main(argv=None):
269291
action=StringToListAction,
270292
type=str,
271293
help="comma-separated list of checkers to disable",
294+
default="",
272295
)
273296
checker_group.add_argument(
274297
"-r",
@@ -277,6 +300,7 @@ def main(argv=None):
277300
action=StringToListAction,
278301
type=str,
279302
help="comma-separated list of checkers to enable",
303+
default="",
280304
)
281305

282306
deprecated_group = parser.add_argument_group("Deprecated")
@@ -285,43 +309,13 @@ def main(argv=None):
285309
"--extract",
286310
action="store_true",
287311
help="autoextract compressed files",
312+
default=True,
288313
)
289314

290-
defaults = {
291-
"directory": "",
292-
"exclude": [],
293-
"input_file": "",
294-
"log_level": "info",
295-
"format": "console",
296-
"cvss": 0,
297-
"severity": "low",
298-
"update": "daily",
299-
"extract": True,
300-
"disable_version_check": False,
301-
"skips": "",
302-
"runs": "",
303-
"quiet": False,
304-
"output_file": "",
305-
"html_theme": "",
306-
"report": False,
307-
"package_list": "",
308-
"append": False,
309-
"tag": "",
310-
"merge": None,
311-
"backport_fix": "",
312-
"available_fix": "",
313-
"nvd": "api",
314-
"nvd_api_key": "",
315-
"filter": [],
316-
"affected_versions": 0,
317-
"sbom": "spdx",
318-
"sbom_file": "",
319-
"offline": False,
320-
}
321-
322315
with ErrorHandler(mode=ErrorMode.NoTrace):
323316
raw_args = parser.parse_args(argv[1:])
324317
args = {key: value for key, value in vars(raw_args).items() if value}
318+
defaults = {key: parser.get_default(key) for key in vars(raw_args)}
325319

326320
configs = {}
327321
if args.get("config"):

cve_bin_tool/helper_script.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def main(argv=None):
334334
"filenames",
335335
help="files to scan",
336336
nargs="+",
337+
default=[],
337338
)
338339

339340
# product-name args
@@ -343,6 +344,7 @@ def main(argv=None):
343344
help="provide product-name that would be searched",
344345
dest="product_name",
345346
action="store",
347+
default=None,
346348
)
347349

348350
# version-name args
@@ -352,6 +354,7 @@ def main(argv=None):
352354
help="provide version that would be searched",
353355
dest="version_number",
354356
action="store",
357+
default=None,
355358
)
356359

357360
# log level args
@@ -362,6 +365,7 @@ def main(argv=None):
362365
dest="log_level",
363366
action="store",
364367
choices=["debug", "info", "warning", "error", "critical"],
368+
default="warning",
365369
)
366370

367371
# contains-patterns string length args
@@ -373,17 +377,10 @@ def main(argv=None):
373377
default=40,
374378
)
375379

376-
defaults = {
377-
"filenames": [],
378-
"product_name": None,
379-
"version_number": None,
380-
"log_level": "warning",
381-
"string_length": 40,
382-
}
383-
384380
with ErrorHandler(mode=ErrorMode.NoTrace):
385381
raw_args = parser.parse_args(argv[1:])
386382
args = {key: value for key, value in vars(raw_args).items() if value}
383+
defaults = {key: parser.get_default(key) for key in vars(raw_args)}
387384

388385
args = ChainMap(args, defaults)
389386

0 commit comments

Comments
 (0)