Skip to content

feat: improve locality of defaults (#1352) #1560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 29 additions & 35 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ def main(argv=None):
action="store",
choices=["api", "json"],
help="choose method for getting CVE lists from NVD",
default="api",
)
nvd_database_group.add_argument(
"-u",
"--update",
action="store",
choices=["now", "daily", "never", "latest"],
help="update schedule for NVD database (default: daily)",
default="daily",
)
nvd_database_group.add_argument(
"--nvd-api-key",
Expand All @@ -110,7 +112,7 @@ def main(argv=None):

input_group = parser.add_argument_group("Input")
input_group.add_argument(
"directory", help="directory to scan", nargs="?", default=None
"directory", help="directory to scan", nargs="?", default=""
)
input_group.add_argument(
"-i",
Expand All @@ -136,11 +138,16 @@ def main(argv=None):
"--sbom-file",
action="store",
help="provide sbom filename",
default="",
)

output_group = parser.add_argument_group("Output")
output_group.add_argument(
"-q", "--quiet", action="store_true", help="suppress output"
"-q",
"--quiet",
action="store_true",
help="suppress output",
default=False,
)
output_group.add_argument(
"-l",
Expand All @@ -149,42 +156,49 @@ def main(argv=None):
dest="log_level",
action="store",
choices=["debug", "info", "warning", "error", "critical"],
default="info",
)
output_group.add_argument(
"-o",
"--output-file",
action="store",
help="provide output filename (default: output to stdout)",
default="",
)
output_group.add_argument(
"--html-theme",
action="store",
help="provide custom theme directory for HTML Report",
default="",
)
output_group.add_argument(
"-f",
"--format",
action="store",
choices=["csv", "json", "console", "html", "pdf"],
help="update output format (default: console)",
default="console",
)
output_group.add_argument(
"-c",
"--cvss",
action="store",
help="minimum CVSS score (as integer in range 0 to 10) to report (default: 0)",
default=0,
)
output_group.add_argument(
"-S",
"--severity",
action="store",
choices=["low", "medium", "high", "critical"],
help="minimum CVE severity to report (default: low)",
default="low",
)
output_group.add_argument(
"--report",
action="store_true",
help="Produces a report even if there are no CVE for the respective output format",
default=False,
)
output_group.add_argument(
"-A",
Expand All @@ -195,6 +209,7 @@ def main(argv=None):
choices=get_available_fix_supported_distros(),
metavar="<distro_name>-<distro_version_name>",
help="Lists available fixes of the package from Linux distribution",
default="",
)
output_group.add_argument(
"-b",
Expand All @@ -205,6 +220,7 @@ def main(argv=None):
choices=get_backport_supported_distros(),
metavar="<distro_name>-<distro_version_name>",
help="Lists backported fixes if available from Linux distribution",
default="",
)
output_group.add_argument(
"--affected-versions",
Expand All @@ -218,18 +234,20 @@ def main(argv=None):
"--exclude",
action=StringToListAction,
help="Comma separated Exclude directory path",
default=None,
default=[],
)
parser.add_argument("-V", "--version", action="version", version=VERSION)
parser.add_argument(
"--disable-version-check",
action="store_true",
help="skips checking for a new version",
default=False,
)
parser.add_argument(
"--offline",
action="store_true",
help="operate in offline mode",
default=False,
)

merge_report_group = parser.add_argument_group(
Expand All @@ -241,24 +259,28 @@ def main(argv=None):
nargs="?",
const=True,
help="save output as intermediate report in json format",
default=False,
)
merge_report_group.add_argument(
"-t",
"--tag",
action="store",
help="add a unique tag to differentiate between multiple intermediate reports",
default="",
)
merge_report_group.add_argument(
"-m",
"--merge",
action=StringToListAction,
help="comma separated intermediate reports path for merging",
default=None,
)
merge_report_group.add_argument(
"-F",
"--filter",
action=StringToListAction,
help="comma separated tag string for filtering intermediate reports",
default=[],
)

checker_group = parser.add_argument_group("Checkers")
Expand All @@ -269,6 +291,7 @@ def main(argv=None):
action=StringToListAction,
type=str,
help="comma-separated list of checkers to disable",
default="",
)
checker_group.add_argument(
"-r",
Expand All @@ -277,6 +300,7 @@ def main(argv=None):
action=StringToListAction,
type=str,
help="comma-separated list of checkers to enable",
default="",
)

deprecated_group = parser.add_argument_group("Deprecated")
Expand All @@ -285,43 +309,13 @@ def main(argv=None):
"--extract",
action="store_true",
help="autoextract compressed files",
default=True,
)

defaults = {
"directory": "",
"exclude": [],
"input_file": "",
"log_level": "info",
"format": "console",
"cvss": 0,
"severity": "low",
"update": "daily",
"extract": True,
"disable_version_check": False,
"skips": "",
"runs": "",
"quiet": False,
"output_file": "",
"html_theme": "",
"report": False,
"package_list": "",
"append": False,
"tag": "",
"merge": None,
"backport_fix": "",
"available_fix": "",
"nvd": "api",
"nvd_api_key": "",
"filter": [],
"affected_versions": 0,
"sbom": "spdx",
"sbom_file": "",
"offline": False,
}

with ErrorHandler(mode=ErrorMode.NoTrace):
raw_args = parser.parse_args(argv[1:])
args = {key: value for key, value in vars(raw_args).items() if value}
defaults = {key: parser.get_default(key) for key in vars(raw_args)}

configs = {}
if args.get("config"):
Expand Down
13 changes: 5 additions & 8 deletions cve_bin_tool/helper_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def main(argv=None):
"filenames",
help="files to scan",
nargs="+",
default=[],
)

# product-name args
Expand All @@ -343,6 +344,7 @@ def main(argv=None):
help="provide product-name that would be searched",
dest="product_name",
action="store",
default=None,
)

# version-name args
Expand All @@ -352,6 +354,7 @@ def main(argv=None):
help="provide version that would be searched",
dest="version_number",
action="store",
default=None,
)

# log level args
Expand All @@ -362,6 +365,7 @@ def main(argv=None):
dest="log_level",
action="store",
choices=["debug", "info", "warning", "error", "critical"],
default="warning",
)

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

defaults = {
"filenames": [],
"product_name": None,
"version_number": None,
"log_level": "warning",
"string_length": 40,
}

with ErrorHandler(mode=ErrorMode.NoTrace):
raw_args = parser.parse_args(argv[1:])
args = {key: value for key, value in vars(raw_args).items() if value}
defaults = {key: parser.get_default(key) for key in vars(raw_args)}

args = ChainMap(args, defaults)

Expand Down