mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
remove print flush for better performance. Roll json.JSONDecodeError into the parse try/except block
This commit is contained in:
35
jc/cli.py
35
jc/cli.py
@ -612,7 +612,7 @@ def main():
|
|||||||
jc.utils.error_message('Missing piped data. Use "jc -h" for help.')
|
jc.utils.error_message('Missing piped data. Use "jc -h" for help.')
|
||||||
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||||
|
|
||||||
# parse the data
|
# parse and print to stdout
|
||||||
try:
|
try:
|
||||||
# differentiate between regular and streaming parsers
|
# differentiate between regular and streaming parsers
|
||||||
|
|
||||||
@ -624,8 +624,7 @@ def main():
|
|||||||
pretty=pretty,
|
pretty=pretty,
|
||||||
env_colors=jc_colors,
|
env_colors=jc_colors,
|
||||||
mono=mono,
|
mono=mono,
|
||||||
piped_out=piped_output()),
|
piped_out=piped_output()))
|
||||||
flush=True)
|
|
||||||
|
|
||||||
sys.exit(combined_exit_code(magic_exit_code, 0))
|
sys.exit(combined_exit_code(magic_exit_code, 0))
|
||||||
|
|
||||||
@ -633,6 +632,13 @@ def main():
|
|||||||
else:
|
else:
|
||||||
data = magic_stdout or sys.stdin.read()
|
data = magic_stdout or sys.stdin.read()
|
||||||
result = parser.parse(data, raw=raw, quiet=quiet)
|
result = parser.parse(data, raw=raw, quiet=quiet)
|
||||||
|
print(json_out(result,
|
||||||
|
pretty=pretty,
|
||||||
|
env_colors=jc_colors,
|
||||||
|
mono=mono,
|
||||||
|
piped_out=piped_output()))
|
||||||
|
|
||||||
|
sys.exit(combined_exit_code(magic_exit_code, 0))
|
||||||
|
|
||||||
except (ParseError, LibraryNotInstalled) as e:
|
except (ParseError, LibraryNotInstalled) as e:
|
||||||
if debug:
|
if debug:
|
||||||
@ -644,6 +650,15 @@ def main():
|
|||||||
' For details use the -d or -dd option. Use "jc -h" for help.')
|
' For details use the -d or -dd option. Use "jc -h" for help.')
|
||||||
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||||
|
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
if debug:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
jc.utils.error_message(
|
||||||
|
'There was an issue generating the JSON output.\n'
|
||||||
|
' For details use the -d or -dd option.')
|
||||||
|
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if debug:
|
if debug:
|
||||||
raise
|
raise
|
||||||
@ -653,20 +668,6 @@ def main():
|
|||||||
' For details use the -d or -dd option. Use "jc -h" for help.')
|
' For details use the -d or -dd option. Use "jc -h" for help.')
|
||||||
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||||
|
|
||||||
# output the json
|
|
||||||
try:
|
|
||||||
print(json_out(result, pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
|
||||||
sys.exit(combined_exit_code(magic_exit_code, 0))
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
if debug:
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
jc.utils.error_message(
|
|
||||||
'There was an issue generating the JSON output.\n'
|
|
||||||
' For details use the -d or -dd option.')
|
|
||||||
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user