summaryrefslogtreecommitdiff
path: root/patternutils/commands/pjson.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--patternutils/commands/pjson.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py
index a6373ac..73786a4 100644
--- a/patternutils/commands/pjson.py
+++ b/patternutils/commands/pjson.py
@@ -84,23 +84,24 @@ def pjson(
click.secho(e.msg, fg="red", err=True)
raise SystemExit
- has_no_key = False
- has_no_match = False
-
if stream:
data = map(utils.json_loads, read_from) # type: ignore
else:
- data = utils.json_loads(read_from.read())
+ data = utils.json_loads(read_from.read()) # type: ignore
matches = []
+ has_no_key = False
+ has_no_match = False
+ has_empty_data = False
for line in data:
+
if not line:
- if abort_on_empty_data:
- click.echo(f"{line} has no input.", fg="red", err=True)
+ has_empty_data = True
+ click.secho(f"{line} has no input.", fg="red", err=True)
+ if stream and abort_on_empty_data:
raise SystemExit
- else:
- continue
+ continue
try:
match = apply_regex(line, key, regex_pattern_c)
@@ -120,7 +121,11 @@ def pjson(
matches.append(line)
if not stream:
- if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match):
+ if (
+ (abort_on_no_key and has_no_key)
+ or (abort_on_no_match and has_no_match)
+ or (abort_on_empty_data and has_empty_data)
+ ):
raise SystemExit
click.echo(utils.json_dumps(matches, human_readable))