Skip to content
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

feat: console output to a file #1632

Merged
merged 12 commits into from
May 31, 2022
5 changes: 3 additions & 2 deletions cve_bin_tool/output_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..log import LOGGER
from ..util import ProductInfo, Remarks
from ..version import VERSION
from .console import output_console
from .console import output_console_wrap
from .html import output_html
from .util import (
add_extension_if_not,
Expand Down Expand Up @@ -372,11 +372,12 @@ def output_cves(self, outfile, output_type="console"):
outfile,
)
else: # console, or anything else that is unrecognised
output_console(
output_console_wrap(
self.all_cve_data,
self.all_cve_version_info,
self.time_of_last_update,
self.affected_versions,
outfile,
)

if isinstance(self.append, str):
Expand Down
16 changes: 16 additions & 0 deletions cve_bin_tool/output_engine/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def format_version_range(version_info: VersionInfo) -> str:
return "-"


def output_console_wrap(*args):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of nitpicky but... I think we should leave the "public" function as output_console in order to match output_html and the others. Makes a better API that way, although it's sort of an informal one. You could rename the internal one to _output_console_nowrap or something to make it more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should this have a type hint for args?

"""wrapper function for output_console to enable output to a file"""

ls_args = list(args)
output_file = ls_args[-1]
ls_args.pop()

if output_file:
with open(output_file, "wt") as f:
console = Console(theme=cve_theme, file=f)
ls_args.append(console)
output_console(*ls_args)
else:
output_console(*ls_args)


def output_console(
all_cve_data: Dict[ProductInfo, CVEData],
all_cve_version_info: Dict[str, VersionInfo],
Expand Down