diff options
| -rw-r--r-- | patternutils/commands/pjson.py | 14 |
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: |
