summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2020-12-12 17:06:40 +0100
committerDennis Fink2020-12-12 17:06:40 +0100
commitc6d55b5aa7b855a850d2e9482406bf46f1508a0e (patch)
treea40238c13e73c3c00bd3a48f1266b23ecdd52941
parentc3c714ae285cd42b0c7a2e102c590f316fcca835 (diff)
downloadpatternutils-c6d55b5aa7b855a850d2e9482406bf46f1508a0e.tar.gz
patternutils-c6d55b5aa7b855a850d2e9482406bf46f1508a0e.zip
Add --abort-on-empty-input to pjson
-rw-r--r--patternutils/commands/pjson.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py
index 66a626f..a6373ac 100644
--- a/patternutils/commands/pjson.py
+++ b/patternutils/commands/pjson.py
@@ -47,6 +47,12 @@ def apply_regex(
help="exit if a value does not match the REGEX_PATTERN",
)
@click.option(
+ "--abort-on-empty-data",
+ is_flag=True,
+ default=False,
+ help="exit if the data is empty",
+)
+@click.option(
"--human-readable",
is_flag=True,
default=False,
@@ -65,6 +71,7 @@ def pjson(
stream: bool,
abort_on_no_key: bool,
abort_on_no_match: bool,
+ abort_on_empty_data: bool,
human_readable: bool,
verbose: bool,
) -> None:
@@ -88,6 +95,13 @@ def pjson(
matches = []
for line in data:
+ if not line:
+ if abort_on_empty_data:
+ click.echo(f"{line} has no input.", fg="red", err=True)
+ raise SystemExit
+ else:
+ continue
+
try:
match = apply_regex(line, key, regex_pattern_c)
except KeyError: