mirror of
https://github.com/httpie/cli.git
synced 2025-04-16 07:18:35 +02:00
exit 0
constant: OK
=> SUCCESS
to avoid confusion w/ HTTP 200 OK
This commit is contained in:
parent
96444f3345
commit
b596fedf13
@ -8,8 +8,8 @@ __licence__ = 'BSD'
|
|||||||
|
|
||||||
|
|
||||||
class ExitStatus:
|
class ExitStatus:
|
||||||
"""Exit status code constants."""
|
"""Program exit code constants."""
|
||||||
OK = 0
|
SUCCESS = 0
|
||||||
ERROR = 1
|
ERROR = 1
|
||||||
PLUGIN_ERROR = 7
|
PLUGIN_ERROR = 7
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def get_exit_status(http_status, follow=False):
|
|||||||
# Server Error
|
# Server Error
|
||||||
return ExitStatus.ERROR_HTTP_5XX
|
return ExitStatus.ERROR_HTTP_5XX
|
||||||
else:
|
else:
|
||||||
return ExitStatus.OK
|
return ExitStatus.SUCCESS
|
||||||
|
|
||||||
|
|
||||||
def print_debug_info(env):
|
def print_debug_info(env):
|
||||||
@ -82,7 +82,7 @@ def program(args, env, log_error):
|
|||||||
:return: status code
|
:return: status code
|
||||||
|
|
||||||
"""
|
"""
|
||||||
exit_status = ExitStatus.OK
|
exit_status = ExitStatus.SUCCESS
|
||||||
downloader = None
|
downloader = None
|
||||||
show_traceback = args.debug or args.traceback
|
show_traceback = args.debug or args.traceback
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ def program(args, env, log_error):
|
|||||||
http_status=response.status_code,
|
http_status=response.status_code,
|
||||||
follow=args.follow
|
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(
|
log_error(
|
||||||
'HTTP %s %s', response.raw.status, response.raw.reason,
|
'HTTP %s %s', response.raw.status, response.raw.reason,
|
||||||
level='warning'
|
level='warning'
|
||||||
@ -143,7 +143,7 @@ def program(args, env, log_error):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if downloader and exit_status == ExitStatus.OK:
|
if downloader and exit_status == ExitStatus.SUCCESS:
|
||||||
# Last response body download.
|
# Last response body download.
|
||||||
download_stream, download_to = downloader.start(final_response)
|
download_stream, download_to = downloader.start(final_response)
|
||||||
write_stream(
|
write_stream(
|
||||||
@ -202,9 +202,9 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
|||||||
if include_debug_info:
|
if include_debug_info:
|
||||||
print_debug_info(env)
|
print_debug_info(env)
|
||||||
if args == ['--debug']:
|
if args == ['--debug']:
|
||||||
return ExitStatus.OK
|
return ExitStatus.SUCCESS
|
||||||
|
|
||||||
exit_status = ExitStatus.OK
|
exit_status = ExitStatus.SUCCESS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
parsed_args = parser.parse_args(args=args, env=env)
|
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
|
raise
|
||||||
exit_status = ExitStatus.ERROR_CTRL_C
|
exit_status = ExitStatus.ERROR_CTRL_C
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
if e.code != ExitStatus.OK:
|
if e.code != ExitStatus.SUCCESS:
|
||||||
env.stderr.write('\n')
|
env.stderr.write('\n')
|
||||||
if include_traceback:
|
if include_traceback:
|
||||||
raise
|
raise
|
||||||
@ -232,7 +232,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
|||||||
raise
|
raise
|
||||||
exit_status = ExitStatus.ERROR_CTRL_C
|
exit_status = ExitStatus.ERROR_CTRL_C
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
if e.code != ExitStatus.OK:
|
if e.code != ExitStatus.SUCCESS:
|
||||||
env.stderr.write('\n')
|
env.stderr.write('\n')
|
||||||
if include_traceback:
|
if include_traceback:
|
||||||
raise
|
raise
|
||||||
|
@ -21,13 +21,13 @@ def test_keyboard_interrupt_in_program_exit_status(httpbin):
|
|||||||
def test_ok_response_exits_0(httpbin):
|
def test_ok_response_exits_0(httpbin):
|
||||||
r = http('GET', httpbin.url + '/get')
|
r = http('GET', httpbin.url + '/get')
|
||||||
assert HTTP_OK in r
|
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):
|
def test_error_response_exits_0_without_check_status(httpbin):
|
||||||
r = http('GET', httpbin.url + '/status/500')
|
r = http('GET', httpbin.url + '/status/500')
|
||||||
assert '500 INTERNAL SERVER ERRO' in r
|
assert '500 INTERNAL SERVER ERROR' in r
|
||||||
assert r.exit_status == ExitStatus.OK
|
assert r.exit_status == ExitStatus.SUCCESS
|
||||||
assert not r.stderr
|
assert not r.stderr
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ def test_3xx_check_status_redirects_allowed_exits_0(httpbin):
|
|||||||
error_exit_ok=True)
|
error_exit_ok=True)
|
||||||
# The redirect will be followed so 200 is expected.
|
# The redirect will be followed so 200 is expected.
|
||||||
assert HTTP_OK in r
|
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):
|
def test_4xx_check_status_exits_4(httpbin):
|
||||||
|
@ -10,19 +10,19 @@ import httpie
|
|||||||
|
|
||||||
def test_debug():
|
def test_debug():
|
||||||
r = http('--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
|
assert 'HTTPie %s' % httpie.__version__ in r.stderr
|
||||||
|
|
||||||
|
|
||||||
def test_help():
|
def test_help():
|
||||||
r = http('--help', error_exit_ok=True)
|
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
|
assert 'https://github.com/jakubroztocil/httpie/issues' in r
|
||||||
|
|
||||||
|
|
||||||
def test_version():
|
def test_version():
|
||||||
r = http('--version', error_exit_ok=True)
|
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
|
# FIXME: py3 has version in stdout, py2 in stderr
|
||||||
assert httpie.__version__ == r.stderr.strip() + r.strip()
|
assert httpie.__version__ == r.stderr.strip() + r.strip()
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ class TestLineEndings:
|
|||||||
|
|
||||||
def test_CRLF_formatted_response(self, httpbin):
|
def test_CRLF_formatted_response(self, httpbin):
|
||||||
r = http('--pretty=format', 'GET', httpbin.url + '/get')
|
r = http('--pretty=format', 'GET', httpbin.url + '/get')
|
||||||
assert r.exit_status == ExitStatus.OK
|
assert r.exit_status == ExitStatus.SUCCESS
|
||||||
self._validate_crlf(r)
|
self._validate_crlf(r)
|
||||||
|
|
||||||
def test_CRLF_ugly_request(self, httpbin):
|
def test_CRLF_ugly_request(self, httpbin):
|
||||||
|
@ -219,7 +219,7 @@ def http(*args, **kwargs):
|
|||||||
sys.stderr.write(stderr.read())
|
sys.stderr.write(stderr.read())
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
if not error_exit_ok and exit_status != ExitStatus.OK:
|
if not error_exit_ok and exit_status != ExitStatus.SUCCESS:
|
||||||
dump_stderr()
|
dump_stderr()
|
||||||
raise ExitStatusError(
|
raise ExitStatusError(
|
||||||
'httpie.core.main() unexpectedly returned'
|
'httpie.core.main() unexpectedly returned'
|
||||||
@ -243,7 +243,7 @@ def http(*args, **kwargs):
|
|||||||
r.stderr = stderr.read()
|
r.stderr = stderr.read()
|
||||||
r.exit_status = exit_status
|
r.exit_status = exit_status
|
||||||
|
|
||||||
if r.exit_status != ExitStatus.OK:
|
if r.exit_status != ExitStatus.SUCCESS:
|
||||||
sys.stderr.write(r.stderr)
|
sys.stderr.write(r.stderr)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
Loading…
Reference in New Issue
Block a user