From 603d9ddc05cd81cb9df8a87cf73bf5c0e7b609f0 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Fri, 1 Nov 2024 11:47:28 -0700 Subject: [PATCH] Set exit code to 0 or 1 based on results If results are found, return an exit code of 1. Return 0 otherwise. Signed-off-by: Eric Brown --- precli/cli/main.py | 5 ++++- tests/unit/cli/test_main.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/precli/cli/main.py b/precli/cli/main.py index 8fda7730..47226af2 100644 --- a/precli/cli/main.py +++ b/precli/cli/main.py @@ -298,7 +298,10 @@ def main(): if args.gist is True: create_gist(file, renderer) - sys.exit(0) + if run.results: + sys.exit(1) + else: + sys.exit(0) if __name__ == "__main__": diff --git a/tests/unit/cli/test_main.py b/tests/unit/cli/test_main.py index ac85bda8..0d608619 100644 --- a/tests/unit/cli/test_main.py +++ b/tests/unit/cli/test_main.py @@ -97,6 +97,13 @@ def test_main_recursive_flag(self, monkeypatch): main.main() assert excinfo.value.code == 0 + def test_main_exit_code_0(self, monkeypatch): + temp_dir = tempfile.mkdtemp() + monkeypatch.setattr("sys.argv", ["precli", temp_dir]) + with pytest.raises(SystemExit) as excinfo: + main.main() + assert excinfo.value.code == 0 + def test_main_version(self, monkeypatch, capsys): monkeypatch.setattr("sys.argv", ["precli", "--version"]) with pytest.raises(SystemExit) as excinfo: