1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

only print _meta object if -q or quiet flag is used. Also, add message to the end of exceptions informing of the -q option to ignore errors

This commit is contained in:
Kelly Brazil
2021-09-12 17:30:56 -07:00
parent 787df51239
commit 1d8cfae89f

View File

@ -34,7 +34,7 @@ Schema:
"date": string, "date": string,
"epoch": integer, # naive timestamp if date field exists and can be converted "epoch": integer, # naive timestamp if date field exists and can be converted
"epoch_utc": integer, # timezone aware timestamp if date field is in UTC and can be converted "epoch_utc": integer, # timezone aware timestamp if date field is in UTC and can be converted
"_meta": "_meta": # This object only exists if using -q or quiet=True
{ {
"success": booean, # true if successfully parsed, false if error "success": booean, # true if successfully parsed, false if error
"error_msg": string, # exists if "success" is false "error_msg": string, # exists if "success" is false
@ -195,16 +195,19 @@ def parse(data, raw=False, quiet=False):
output_line['group'] = parsed_line[3] output_line['group'] = parsed_line[3]
output_line['size'] = parsed_line[4] output_line['size'] = parsed_line[4]
output_line['date'] = ' '.join(parsed_line[5:8]) output_line['date'] = ' '.join(parsed_line[5:8])
output_line['_meta'] = {'success': True}
if quiet:
output_line['_meta'] = {'success': True}
if raw: if raw:
yield output_line yield output_line
else: else:
yield _process(output_line) yield _process(output_line)
except Exception: except Exception as e:
if not quiet: if not quiet:
raise e.args = (str(e) + '... Try the quiet option (-q) to ignore errors.',)
raise e
else: else:
yield { yield {
'_meta': '_meta':