mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
handle case where the user pipes data and uses magic syntax simultaneously
This commit is contained in:
13
jc/cli.py
13
jc/cli.py
@ -585,11 +585,16 @@ def main():
|
|||||||
jc.utils.error_message('Missing or incorrect arguments. Use "jc -h" for help.')
|
jc.utils.error_message('Missing or incorrect arguments. 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
|
# check for input errors (pipe vs magic)
|
||||||
if sys.stdin.isatty() and magic_stdout is None:
|
if not sys.stdin.isatty() and magic_stdout:
|
||||||
|
jc.utils.error_message('Piped data and Magic syntax used simultaneously. Use "jc -h" for help.')
|
||||||
|
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||||
|
|
||||||
|
elif sys.stdin.isatty() and magic_stdout is None:
|
||||||
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
|
||||||
data = magic_stdout or sys.stdin.read()
|
data = magic_stdout or sys.stdin.read()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -613,7 +618,9 @@ def main():
|
|||||||
if debug:
|
if debug:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
jc.utils.error_message('There was an issue generating the JSON output. For details use the -d or -dd option.')
|
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))
|
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user