Skip to content

Commit

Permalink
Merge pull request #44 from RedHatProductSecurity/json-output-in-cli
Browse files Browse the repository at this point in the history
Add option to view JSON of a CVSS vector
  • Loading branch information
mprpic authored Jun 20, 2023
2 parents dd31b44 + 070883e commit ff2d385
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cvss/cvss_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from __future__ import print_function

import argparse
import json

from cvss import CVSSError, ask_interactively

Expand All @@ -26,6 +27,9 @@ def main():
parser.add_argument(
"-n", "--no-colors", action="store_true", help="do not use terminal coloring"
)
parser.add_argument(
"-j", "--json", action="store_true", help="output vector in JSON format"
)
args = parser.parse_args()

# Import the correct CVSS module
Expand Down Expand Up @@ -70,6 +74,9 @@ def main():
print(scores[i])
print("Cleaned vector: ", cvss_vector.clean_vector())
print("Red Hat vector: ", cvss_vector.rh_vector())
if args.json:
json_output = json.dumps(cvss_vector.as_json(sort=True, minimal=True), indent=2)
print("CVSS vector in JSON:", json_output, sep="\n")
except (KeyboardInterrupt, EOFError):
print()

Expand Down
2 changes: 1 addition & 1 deletion cvss/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def ask_interactively(version=3.1, all_metrics=False, no_colors=False):
while True:
print(METRICS_ABBREVIATIONS[metric] + ":", end=" ")
print("/".join(values), end=" ")
input_value = string_input().upper()
input_value = string_input().strip().upper()
if not input_value:
if version == 2:
input_value = "ND"
Expand Down

0 comments on commit ff2d385

Please sign in to comment.