From c3c714ae285cd42b0c7a2e102c590f316fcca835 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 17:02:52 +0100 Subject: Fix stream in pjson, pmatch and prss --- patternutils/commands/pjson.py | 7 ++++--- patternutils/commands/pmatch.py | 7 ++++--- patternutils/commands/prss.py | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index a7bf069..66a626f 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -105,7 +105,8 @@ def pjson( else: matches.append(line) - if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match): - raise SystemExit + if not stream: + if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match): + raise SystemExit - click.echo(utils.json_dumps(matches, human_readable)) + click.echo(utils.json_dumps(matches, human_readable)) diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index 8a2e89f..c217c36 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -135,9 +135,10 @@ def pmatch( else: matches.append(match) - if has_invalid_matches and abort_on_no_match: - raise SystemExit - click.echo(utils.json_dumps(matches, human_readable)) + if not stream: + if has_invalid_matches and abort_on_no_match: + raise SystemExit + click.echo(utils.json_dumps(matches, human_readable)) if __name__ == "__main__": diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 6c7d88b..a176587 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -132,10 +132,11 @@ def prss( else: matches.append(m) - if abort_on_no_file and has_no_file: - raise SystemExit + if not stream: + if abort_on_no_file and has_no_file: + raise SystemExit - click.echo(utils.json_dumps(matches, human_readable)) + click.echo(utils.json_dumps(matches, human_readable)) if __name__ == "__main__": -- cgit v1.3.1