From 965cce9af231679662df9c0488eaff2ece8f463c Mon Sep 17 00:00:00 2001 From: Mariusz Skoneczko Date: Sun, 1 Mar 2020 11:03:53 +1100 Subject: [PATCH 1/5] Use `-o` for output filename, `-f` for format --- cve_bin_tool/cli.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/cve_bin_tool/cli.py b/cve_bin_tool/cli.py index cf583f31e4..9fee1306fb 100755 --- a/cve_bin_tool/cli.py +++ b/cve_bin_tool/cli.py @@ -328,19 +328,15 @@ def main(argv=None, outfile=sys.stdout): choices=["debug", "info", "warning", "error", "critical"], ) output_group.add_argument( - "-o", - "--output", - action="store", - choices=["csv", "json", "console"], - default="console", - help="update output format (default: console)", + "-o", "--output", action="store", 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()}", @@ -484,16 +480,16 @@ 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) if ( LOGGER.getEffectiveLevel() != logging.CRITICAL - and args.output == "console" + and args.format == "console" ): output.output_cves(outfile) # If the args are passed for csv we will generate a CSV output - if args.output == "csv": + if args.format == "csv": output.output_csv() # Use the number of files with known cves as error code From 1b98d708a7977e0ae86cbb1827df27e15f3b43de Mon Sep 17 00:00:00 2001 From: Mariusz Skoneczko Date: Sun, 1 Mar 2020 11:09:00 +1100 Subject: [PATCH 2/5] Document the `-o` and `-f` flags --- MANUAL.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MANUAL.md b/MANUAL.md index 74ff64c1ba..a8244e55cf 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -18,6 +18,10 @@ Possible output levels: Other options: ``` -h, --help show help message and exit + -o OUTPUT, --output OUTPUT + provide output filename + -f {csv,json,console}, --format {csv,json,console} + update output format (default: console) -x, --extract autoextract compressed files -s SKIPS, --skips SKIPS comma-separated list of checkers to disable @@ -159,6 +163,16 @@ This option controls the frequency of updates for the CVE data from the National Output modes ------------ +### -o OUTPUT, --output OUTPUT + +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 From b931c416124fafc33db77db37eb5e1a38eff657c Mon Sep 17 00:00:00 2001 From: Mariusz Skoneczko Date: Thu, 5 Mar 2020 11:33:25 +1100 Subject: [PATCH 3/5] Ensure file is correctly --- cve_bin_tool/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cve_bin_tool/cli.py b/cve_bin_tool/cli.py index 9f111a5409..9084bea166 100755 --- a/cve_bin_tool/cli.py +++ b/cve_bin_tool/cli.py @@ -489,7 +489,7 @@ def main(argv=None, outfile=sys.stdout): 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. From 5bf4e0b06ad6f205b148d57b9e5dca73328a66b1 Mon Sep 17 00:00:00 2001 From: Mariusz Skoneczko Date: Thu, 5 Mar 2020 11:35:54 +1100 Subject: [PATCH 4/5] Respect full given filename, do not add extension --- cve_bin_tool/OutputEngine.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cve_bin_tool/OutputEngine.py b/cve_bin_tool/OutputEngine.py index 61c0e2d6ff..1c6ecae111 100644 --- a/cve_bin_tool/OutputEngine.py +++ b/cve_bin_tool/OutputEngine.py @@ -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: From 3d2cda957d074a73be8f890d43d789123c6a20e4 Mon Sep 17 00:00:00 2001 From: Mariusz Skoneczko Date: Thu, 5 Mar 2020 12:36:23 +1100 Subject: [PATCH 5/5] Change output to output-file, maintaining black formatting --- MANUAL.md | 8 ++------ cve_bin_tool/cli.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index 8e3049b932..cc66388b4a 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -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 @@ -43,10 +43,6 @@ Possible output levels: Other options: ``` -h, --help show help message and exit - -o OUTPUT, --output OUTPUT - provide output filename - -f {csv,json,console}, --format {csv,json,console} - update output format (default: console) -v, --version show program's version number and exit -x, --extract autoextract compressed files -s SKIPS, --skips SKIPS @@ -175,7 +171,7 @@ This option controls the frequency of updates for the CVE data from the National Output modes ------------ -### -o OUTPUT, --output OUTPUT +### -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. diff --git a/cve_bin_tool/cli.py b/cve_bin_tool/cli.py index 9084bea166..eb09a0c310 100755 --- a/cve_bin_tool/cli.py +++ b/cve_bin_tool/cli.py @@ -328,7 +328,11 @@ def main(argv=None, outfile=sys.stdout): choices=["debug", "info", "warning", "error", "critical"], ) output_group.add_argument( - "-o", "--output", action="store", default=None, help="provide output filename", + "-o", + "--output-file", + action="store", + default=None, + help="provide output filename", ) output_group.add_argument( "-f", @@ -480,7 +484,9 @@ 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.output) + output = OutputEngine( + modules=scanner.all_cves, filename=args.output_file + ) if ( LOGGER.getEffectiveLevel() != logging.CRITICAL