Skip to content

Use the -o flag to specify the filename #425

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 6 commits into from
Mar 9, 2020
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
12 changes: 11 additions & 1 deletion MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Possible output levels:
-q, --quiet suppress output
-l {debug,info,warning,error,critical}, --log {debug,info,warning,error,critical}
log level
-o {csv,json,console}, --output {csv,json,console}
-o OUTPUT_FILE, --output-file OUTPUT_FILE
update output format (default: console)
-f FILENAME, --filename FILENAME
provide output file name
Expand Down Expand Up @@ -171,6 +171,16 @@ This option controls the frequency of updates for the CVE data from the National
Output modes
------------

### -o OUTPUT_FILE, --output-file OUTPUT_FILE

This option allows you to specify the filename for the report, rather than having CVE Binary Tool generate it by itself.

### -f {csv,json,console}, --format {csv,json,console}

This option allows the CVE Binary Tool to produce a report in an alternate format. This is useful if you have other tools which only take a specific format.

### Output verbosity

The tool has several different output modes, from most information to least as follows:

1. Regular mode (no flag) prints only the final summary of findings
Expand Down
1 change: 0 additions & 1 deletion cve_bin_tool/OutputEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def output_file(self, output="csv"):
if self.filename == None:
self.generate_filename(output)
else:
self.filename = f"{self.filename}.{output}"
# check if the filename already exists
file_list = os.listdir(os.getcwd())
if self.filename in file_list:
Expand Down
22 changes: 12 additions & 10 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@ def main(argv=None, outfile=sys.stdout):
)
output_group.add_argument(
"-o",
"--output",
"--output-file",
action="store",
choices=["csv", "json", "console"],
default="console",
help="update output format (default: console)",
default=None,
help="provide output filename",
)
output_group.add_argument(
"-f",
"--filename",
"--format",
action="store",
default=None,
help="provide output file name",
choices=["csv", "json", "console"],
default="console",
help="update output format (default: console)",
)
parser.add_argument(
"-v", "--version", action="version", version=f"{get_version_string()}",
Expand Down Expand Up @@ -484,16 +484,18 @@ def main(argv=None, outfile=sys.stdout):
LOGGER.info(f"Known CVEs in {affected_string}:")

# Creates a Object for OutputEngine
output = OutputEngine(modules=scanner.all_cves, filename=args.filename)
output = OutputEngine(
modules=scanner.all_cves, filename=args.output_file
)

if (
LOGGER.getEffectiveLevel() != logging.CRITICAL
and args.output == "console"
and args.format == "console"
):
output.output_cves(outfile)
else:
# If the args are passed for csv/json we will generate a file output
output.output_file(args.output)
output.output_file(args.format)

# Use the number of files with known cves as error code
# as requested by folk planning to automate use of this script.
Expand Down