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
|
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 -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 -q and quiet=True options to suppress warnings to stderr
|
||||||
|
- Add -d option to debug parsing issues
|
||||||
- Add compatibility warnings to stderr
|
- Add compatibility warnings to stderr
|
||||||
- Updated lsblk parser to allow parsing of added columns
|
- Updated lsblk parser to allow parsing of added columns
|
||||||
- Updated mount parser: changed 'access' field name to 'options'
|
- Updated mount parser: changed 'access' field name to 'options'
|
||||||
|
18
jc/cli.py
18
jc/cli.py
@ -7,6 +7,7 @@ import sys
|
|||||||
import textwrap
|
import textwrap
|
||||||
import signal
|
import signal
|
||||||
import json
|
import json
|
||||||
|
import jc.utils
|
||||||
import jc.parsers.arp
|
import jc.parsers.arp
|
||||||
import jc.parsers.df
|
import jc.parsers.df
|
||||||
import jc.parsers.dig
|
import jc.parsers.dig
|
||||||
@ -62,6 +63,7 @@ def helptext(message):
|
|||||||
--w w parser
|
--w w parser
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
-d debug - show trace messages
|
||||||
-p pretty print output
|
-p pretty print output
|
||||||
-q quiet - suppress warnings
|
-q quiet - suppress warnings
|
||||||
-r raw JSON output
|
-r raw JSON output
|
||||||
@ -80,11 +82,15 @@ def main():
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
data = sys.stdin.read()
|
data = sys.stdin.read()
|
||||||
|
debug = False
|
||||||
pretty = False
|
pretty = False
|
||||||
quiet = False
|
quiet = False
|
||||||
raw = False
|
raw = False
|
||||||
|
|
||||||
# options
|
# options
|
||||||
|
if '-d' in sys.argv:
|
||||||
|
debug = True
|
||||||
|
|
||||||
if '-p' in sys.argv:
|
if '-p' in sys.argv:
|
||||||
pretty = True
|
pretty = True
|
||||||
|
|
||||||
@ -120,11 +126,23 @@ def main():
|
|||||||
|
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
|
if debug:
|
||||||
for arg in sys.argv:
|
for arg in sys.argv:
|
||||||
if arg in parser_map:
|
if arg in parser_map:
|
||||||
result = parser_map[arg](data, raw=raw, quiet=quiet)
|
result = parser_map[arg](data, raw=raw, quiet=quiet)
|
||||||
found = True
|
found = True
|
||||||
break
|
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:
|
if not found:
|
||||||
helptext('missing or incorrect arguments')
|
helptext('missing or incorrect arguments')
|
||||||
|
Reference in New Issue
Block a user