diff --git a/httpie/core.py b/httpie/core.py index b9c4fe9b..95f53abd 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -163,12 +163,17 @@ def main(args=sys.argv[1:], env=Environment()): env.stderr.write('\n') else: raise - except (KeyboardInterrupt, SystemExit): + except KeyboardInterrupt: if traceback: raise env.stderr.write('\n') exit_status = ExitStatus.ERROR - + except SystemExit as e: + if e.code != ExitStatus.OK: + if traceback: + raise + env.stderr.write('\n') + exit_status = ExitStatus.ERROR except requests.Timeout: exit_status = ExitStatus.ERROR_TIMEOUT error('Request timed out (%ss).', args.timeout) diff --git a/tests/test_httpie.py b/tests/test_httpie.py index 2ee647ea..a5b9041f 100644 --- a/tests/test_httpie.py +++ b/tests/test_httpie.py @@ -14,12 +14,12 @@ class TestHTTPie: def test_help(self): r = http('--help', error_exit_ok=True) - assert r.exit_status == httpie.ExitStatus.ERROR + assert r.exit_status == httpie.ExitStatus.OK assert 'https://github.com/jakubroztocil/httpie/issues' in r def test_version(self): r = http('--version', error_exit_ok=True) - assert r.exit_status == httpie.ExitStatus.ERROR + assert r.exit_status == httpie.ExitStatus.OK # FIXME: py3 has version in stdout, py2 in stderr assert httpie.__version__ == r.stderr.strip() + r.strip()