Skip to content

Commit 258d60e

Browse files
committed
feat: improve locality of defaults
1 parent e36bc96 commit 258d60e

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

cve_bin_tool/cli.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,20 @@ def main(argv=None):
9191
action="store",
9292
choices=["api", "json"],
9393
help="choose method for getting CVE lists from NVD",
94+
default="api",
9495
)
9596
nvd_database_group.add_argument(
9697
"-u",
9798
"--update",
9899
action="store",
99100
choices=["now", "daily", "never", "latest"],
100101
help="update schedule for NVD database (default: daily)",
102+
default="daily",
101103
)
102104

103105
input_group = parser.add_argument_group("Input")
104106
input_group.add_argument(
105-
"directory", help="directory to scan", nargs="?", default=None
107+
"directory", help="directory to scan", nargs="?", default=""
106108
)
107109
input_group.add_argument(
108110
"-i",
@@ -128,11 +130,16 @@ def main(argv=None):
128130
"--sbom-file",
129131
action="store",
130132
help="provide sbom filename",
133+
default="",
131134
)
132135

133136
output_group = parser.add_argument_group("Output")
134137
output_group.add_argument(
135-
"-q", "--quiet", action="store_true", help="suppress output"
138+
"-q",
139+
"--quiet",
140+
action="store_true",
141+
help="suppress output",
142+
default=False,
136143
)
137144
output_group.add_argument(
138145
"-l",
@@ -141,42 +148,49 @@ def main(argv=None):
141148
dest="log_level",
142149
action="store",
143150
choices=["debug", "info", "warning", "error", "critical"],
151+
default="info",
144152
)
145153
output_group.add_argument(
146154
"-o",
147155
"--output-file",
148156
action="store",
149157
help="provide output filename (default: output to stdout)",
158+
default="",
150159
)
151160
output_group.add_argument(
152161
"--html-theme",
153162
action="store",
154163
help="provide custom theme directory for HTML Report",
164+
default="",
155165
)
156166
output_group.add_argument(
157167
"-f",
158168
"--format",
159169
action="store",
160170
choices=["csv", "json", "console", "html", "pdf"],
161171
help="update output format (default: console)",
172+
default="console",
162173
)
163174
output_group.add_argument(
164175
"-c",
165176
"--cvss",
166177
action="store",
167178
help="minimum CVSS score (as integer in range 0 to 10) to report (default: 0)",
179+
default=0,
168180
)
169181
output_group.add_argument(
170182
"-S",
171183
"--severity",
172184
action="store",
173185
choices=["low", "medium", "high", "critical"],
174186
help="minimum CVE severity to report (default: low)",
187+
default="low",
175188
)
176189
output_group.add_argument(
177190
"--report",
178191
action="store_true",
179192
help="Produces a report even if there are no CVE for the respective output format",
193+
default=False,
180194
)
181195
output_group.add_argument(
182196
"-A",
@@ -187,6 +201,7 @@ def main(argv=None):
187201
choices=get_available_fix_supported_distros(),
188202
metavar="<distro_name>-<distro_version_name>",
189203
help="Lists available fixes of the package from Linux distribution",
204+
default="",
190205
)
191206
output_group.add_argument(
192207
"-b",
@@ -197,6 +212,7 @@ def main(argv=None):
197212
choices=get_backport_supported_distros(),
198213
metavar="<distro_name>-<distro_version_name>",
199214
help="Lists backported fixes if available from Linux distribution",
215+
default="",
200216
)
201217
output_group.add_argument(
202218
"--affected-versions",
@@ -210,14 +226,24 @@ def main(argv=None):
210226
"--exclude",
211227
action=StringToListAction,
212228
help="Comma separated Exclude directory path",
213-
default=None,
229+
default=[],
214230
)
215231
parser.add_argument("-V", "--version", action="version", version=VERSION)
216232
parser.add_argument(
217233
"--disable-version-check",
218234
action="store_true",
219235
help="skips checking for a new version",
236+
default=False,
220237
)
238+
<<<<<<< HEAD
239+
=======
240+
parser.add_argument(
241+
"--offline",
242+
action="store_true",
243+
help="operate in offline mode",
244+
default=False,
245+
)
246+
>>>>>>> 33b40fe... feat: improve locality of defaults
221247

222248
merge_report_group = parser.add_argument_group(
223249
"Merge Report", "Arguments related to Intermediate and Merged Reports"
@@ -228,24 +254,28 @@ def main(argv=None):
228254
nargs="?",
229255
const=True,
230256
help="save output as intermediate report in json format",
257+
default=False,
231258
)
232259
merge_report_group.add_argument(
233260
"-t",
234261
"--tag",
235262
action="store",
236263
help="add a unique tag to differentiate between multiple intermediate reports",
264+
default="",
237265
)
238266
merge_report_group.add_argument(
239267
"-m",
240268
"--merge",
241269
action=StringToListAction,
242270
help="comma separated intermediate reports path for merging",
271+
default=None,
243272
)
244273
merge_report_group.add_argument(
245274
"-F",
246275
"--filter",
247276
action=StringToListAction,
248277
help="comma separated tag string for filtering intermediate reports",
278+
default=[],
249279
)
250280

251281
checker_group = parser.add_argument_group("Checkers")
@@ -256,6 +286,7 @@ def main(argv=None):
256286
action=StringToListAction,
257287
type=str,
258288
help="comma-separated list of checkers to disable",
289+
default="",
259290
)
260291
checker_group.add_argument(
261292
"-r",
@@ -264,6 +295,7 @@ def main(argv=None):
264295
action=StringToListAction,
265296
type=str,
266297
help="comma-separated list of checkers to enable",
298+
default="",
267299
)
268300

269301
deprecated_group = parser.add_argument_group("Deprecated")
@@ -272,41 +304,13 @@ def main(argv=None):
272304
"--extract",
273305
action="store_true",
274306
help="autoextract compressed files",
307+
default=True,
275308
)
276309

277-
defaults = {
278-
"directory": "",
279-
"exclude": [],
280-
"input_file": "",
281-
"log_level": "info",
282-
"format": "console",
283-
"cvss": 0,
284-
"severity": "low",
285-
"update": "daily",
286-
"extract": True,
287-
"disable_version_check": False,
288-
"skips": "",
289-
"runs": "",
290-
"quiet": False,
291-
"output_file": "",
292-
"html_theme": "",
293-
"report": False,
294-
"package_list": "",
295-
"append": False,
296-
"tag": "",
297-
"merge": None,
298-
"backport_fix": "",
299-
"available_fix": "",
300-
"nvd": "api",
301-
"filter": [],
302-
"affected_versions": 0,
303-
"sbom": "spdx",
304-
"sbom_file": "",
305-
}
306-
307310
with ErrorHandler(mode=ErrorMode.NoTrace):
308311
raw_args = parser.parse_args(argv[1:])
309312
args = {key: value for key, value in vars(raw_args).items() if value}
313+
defaults = {key: parser.get_default(key) for key in vars(raw_args)}
310314

311315
configs = {}
312316
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)