mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
add -d option
This commit is contained in:
@ -3,6 +3,7 @@ jc changelog
|
||||
201911xx v1.5.1
|
||||
- Add -r and raw=True options. By default, jc will now convert numbers and boolean, if possible, and add other semantic information, while the raw output will keep all values as text and provide a more literal JSON output
|
||||
- Add -q and quiet=True options to suppress warnings to stderr
|
||||
- Add -d option to debug parsing issues
|
||||
- Add compatibility warnings to stderr
|
||||
- Updated lsblk parser to allow parsing of added columns
|
||||
- Updated mount parser: changed 'access' field name to 'options'
|
||||
|
28
jc/cli.py
28
jc/cli.py
@ -7,6 +7,7 @@ import sys
|
||||
import textwrap
|
||||
import signal
|
||||
import json
|
||||
import jc.utils
|
||||
import jc.parsers.arp
|
||||
import jc.parsers.df
|
||||
import jc.parsers.dig
|
||||
@ -62,6 +63,7 @@ def helptext(message):
|
||||
--w w parser
|
||||
|
||||
Options:
|
||||
-d debug - show trace messages
|
||||
-p pretty print output
|
||||
-q quiet - suppress warnings
|
||||
-r raw JSON output
|
||||
@ -80,11 +82,15 @@ def main():
|
||||
exit()
|
||||
|
||||
data = sys.stdin.read()
|
||||
debug = False
|
||||
pretty = False
|
||||
quiet = False
|
||||
raw = False
|
||||
|
||||
# options
|
||||
if '-d' in sys.argv:
|
||||
debug = True
|
||||
|
||||
if '-p' in sys.argv:
|
||||
pretty = True
|
||||
|
||||
@ -120,11 +126,23 @@ def main():
|
||||
|
||||
found = False
|
||||
|
||||
for arg in sys.argv:
|
||||
if arg in parser_map:
|
||||
result = parser_map[arg](data, raw=raw, quiet=quiet)
|
||||
found = True
|
||||
break
|
||||
if debug:
|
||||
for arg in sys.argv:
|
||||
if arg in parser_map:
|
||||
result = parser_map[arg](data, raw=raw, quiet=quiet)
|
||||
found = True
|
||||
break
|
||||
else:
|
||||
for arg in sys.argv:
|
||||
if arg in parser_map:
|
||||
try:
|
||||
parser_name = arg.lstrip('--')
|
||||
result = parser_map[arg](data, raw=raw, quiet=quiet)
|
||||
found = True
|
||||
break
|
||||
except:
|
||||
jc.utils.error_message(f'{parser_name} parser could not parse the input data. Did you use the correct parser?\n For details use the -d option.')
|
||||
exit(1)
|
||||
|
||||
if not found:
|
||||
helptext('missing or incorrect arguments')
|
||||
|
Reference in New Issue
Block a user