From c6d55b5aa7b855a850d2e9482406bf46f1508a0e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 17:06:40 +0100 Subject: Add --abort-on-empty-input to pjson --- patternutils/commands/pjson.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 @@ -46,6 +46,12 @@ def apply_regex( default=False, 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, @@ -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: -- cgit v1.3.1