mirror of https://github.com/crytic/slither
- Fix bug: the json output was always enabled - Move output_json to a shared modulepull/348/head
parent
eb580f1ad9
commit
6f2c8e713f
@ -0,0 +1,36 @@ |
||||
import os |
||||
import json |
||||
import logging |
||||
from slither.utils.colors import yellow |
||||
logger = logging.getLogger("Slither") |
||||
|
||||
def output_json(filename, error, results): |
||||
""" |
||||
|
||||
:param filename: Filename where the json will be written. If None or "-", write to stdout |
||||
:param error: Error to report |
||||
:param results: Results to report |
||||
:param logger: Logger where to log potential info |
||||
:return: |
||||
""" |
||||
# Create our encapsulated JSON result. |
||||
json_result = { |
||||
"success": error is None, |
||||
"error": error, |
||||
"results": results |
||||
} |
||||
|
||||
if filename == "-": |
||||
filename = None |
||||
|
||||
# Determine if we should output to stdout |
||||
if filename is None: |
||||
# Write json to console |
||||
print(json.dumps(json_result)) |
||||
else: |
||||
# Write json to file |
||||
if os.path.isfile(filename): |
||||
logger.info(yellow(f'{filename} exists already, the overwrite is prevented')) |
||||
else: |
||||
with open(filename, 'w', encoding='utf8') as f: |
||||
json.dump(json_result, f, indent=2) |
Loading…
Reference in new issue