1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00

exit 0 constant: OK => SUCCESS to avoid confusion w/ HTTP 200 OK

This commit is contained in:
Jakub Roztocil 2018-11-02 16:07:39 +01:00
parent 96444f3345
commit b596fedf13
6 changed files with 20 additions and 20 deletions

View File

@ -8,8 +8,8 @@ __licence__ = 'BSD'
class ExitStatus:
"""Exit status code constants."""
OK = 0
"""Program exit code constants."""
SUCCESS = 0
ERROR = 1
PLUGIN_ERROR = 7

View File

@ -43,7 +43,7 @@ def get_exit_status(http_status, follow=False):
# Server Error
return ExitStatus.ERROR_HTTP_5XX
else:
return ExitStatus.OK
return ExitStatus.SUCCESS
def print_debug_info(env):
@ -82,7 +82,7 @@ def program(args, env, log_error):
:return: status code
"""
exit_status = ExitStatus.OK
exit_status = ExitStatus.SUCCESS
downloader = None
show_traceback = args.debug or args.traceback
@ -109,7 +109,7 @@ def program(args, env, log_error):
http_status=response.status_code,
follow=args.follow
)
if not env.stdout_isatty and exit_status != ExitStatus.OK:
if not env.stdout_isatty and exit_status != ExitStatus.SUCCESS:
log_error(
'HTTP %s %s', response.raw.status, response.raw.reason,
level='warning'
@ -143,7 +143,7 @@ def program(args, env, log_error):
else:
raise
if downloader and exit_status == ExitStatus.OK:
if downloader and exit_status == ExitStatus.SUCCESS:
# Last response body download.
download_stream, download_to = downloader.start(final_response)
write_stream(
@ -202,9 +202,9 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
if include_debug_info:
print_debug_info(env)
if args == ['--debug']:
return ExitStatus.OK
return ExitStatus.SUCCESS
exit_status = ExitStatus.OK
exit_status = ExitStatus.SUCCESS
try:
parsed_args = parser.parse_args(args=args, env=env)
@ -214,7 +214,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
raise
exit_status = ExitStatus.ERROR_CTRL_C
except SystemExit as e:
if e.code != ExitStatus.OK:
if e.code != ExitStatus.SUCCESS:
env.stderr.write('\n')
if include_traceback:
raise
@ -232,7 +232,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
raise
exit_status = ExitStatus.ERROR_CTRL_C
except SystemExit as e:
if e.code != ExitStatus.OK:
if e.code != ExitStatus.SUCCESS:
env.stderr.write('\n')
if include_traceback:
raise

View File

@ -21,13 +21,13 @@ def test_keyboard_interrupt_in_program_exit_status(httpbin):
def test_ok_response_exits_0(httpbin):
r = http('GET', httpbin.url + '/get')
assert HTTP_OK in r
assert r.exit_status == ExitStatus.OK
assert r.exit_status == ExitStatus.SUCCESS
def test_error_response_exits_0_without_check_status(httpbin):
r = http('GET', httpbin.url + '/status/500')
assert '500 INTERNAL SERVER ERRO' in r
assert r.exit_status == ExitStatus.OK
assert '500 INTERNAL SERVER ERROR' in r
assert r.exit_status == ExitStatus.SUCCESS
assert not r.stderr
@ -55,7 +55,7 @@ def test_3xx_check_status_redirects_allowed_exits_0(httpbin):
error_exit_ok=True)
# The redirect will be followed so 200 is expected.
assert HTTP_OK in r
assert r.exit_status == ExitStatus.OK
assert r.exit_status == ExitStatus.SUCCESS
def test_4xx_check_status_exits_4(httpbin):

View File

@ -10,19 +10,19 @@ import httpie
def test_debug():
r = http('--debug')
assert r.exit_status == httpie.ExitStatus.OK
assert r.exit_status == httpie.ExitStatus.SUCCESS
assert 'HTTPie %s' % httpie.__version__ in r.stderr
def test_help():
r = http('--help', error_exit_ok=True)
assert r.exit_status == httpie.ExitStatus.OK
assert r.exit_status == httpie.ExitStatus.SUCCESS
assert 'https://github.com/jakubroztocil/httpie/issues' in r
def test_version():
r = http('--version', error_exit_ok=True)
assert r.exit_status == httpie.ExitStatus.OK
assert r.exit_status == httpie.ExitStatus.SUCCESS
# FIXME: py3 has version in stdout, py2 in stderr
assert httpie.__version__ == r.stderr.strip() + r.strip()

View File

@ -161,7 +161,7 @@ class TestLineEndings:
def test_CRLF_formatted_response(self, httpbin):
r = http('--pretty=format', 'GET', httpbin.url + '/get')
assert r.exit_status == ExitStatus.OK
assert r.exit_status == ExitStatus.SUCCESS
self._validate_crlf(r)
def test_CRLF_ugly_request(self, httpbin):

View File

@ -219,7 +219,7 @@ def http(*args, **kwargs):
sys.stderr.write(stderr.read())
raise
else:
if not error_exit_ok and exit_status != ExitStatus.OK:
if not error_exit_ok and exit_status != ExitStatus.SUCCESS:
dump_stderr()
raise ExitStatusError(
'httpie.core.main() unexpectedly returned'
@ -243,7 +243,7 @@ def http(*args, **kwargs):
r.stderr = stderr.read()
r.exit_status = exit_status
if r.exit_status != ExitStatus.OK:
if r.exit_status != ExitStatus.SUCCESS:
sys.stderr.write(r.stderr)
return r