Exit with 0 for --version and --help (closes #293).

This commit is contained in:
Jakub Roztocil 2015-01-19 15:39:46 +01:00
parent 0481957715
commit b2ec4f797f
2 changed files with 9 additions and 4 deletions

View File

@ -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)

View File

@ -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()