forked from extern/httpie-cli
Exit with status 130 on CTRL-C
http://www.tldp.org/LDP/abs/html/exitcodes.html #531
This commit is contained in:
parent
b96eba336d
commit
9b23a4ac9a
@ -11,6 +11,7 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
|
||||
|
||||
* Added support for ``curses``-less Python installations.
|
||||
* Fixed ``REQUEST_ITEM`` arg incorrectly being reported as required.
|
||||
* Added 130 ``REQUEST_ITEM`` arg incorrectly being reported as required.
|
||||
|
||||
|
||||
`0.9.6`_ (2016-08-13)
|
||||
|
@ -11,6 +11,10 @@ class ExitStatus:
|
||||
"""Exit status code constants."""
|
||||
OK = 0
|
||||
ERROR = 1
|
||||
|
||||
# 128+2 SIGINT <http://www.tldp.org/LDP/abs/html/exitcodes.html>
|
||||
ERROR_CTRL_C = 130
|
||||
|
||||
ERROR_TIMEOUT = 2
|
||||
ERROR_TOO_MANY_REDIRECTS = 6
|
||||
|
||||
|
@ -10,7 +10,8 @@ def main():
|
||||
from .core import main
|
||||
sys.exit(main())
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(1)
|
||||
from . import ExitStatus
|
||||
sys.exit(ExitStatus.ERROR_CTRL_C)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -212,7 +212,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
||||
env.stderr.write('\n')
|
||||
if include_traceback:
|
||||
raise
|
||||
exit_status = ExitStatus.ERROR
|
||||
exit_status = ExitStatus.ERROR_CTRL_C
|
||||
except SystemExit as e:
|
||||
if e.code != ExitStatus.OK:
|
||||
env.stderr.write('\n')
|
||||
@ -230,7 +230,7 @@ def main(args=sys.argv[1:], env=Environment(), custom_log_error=None):
|
||||
env.stderr.write('\n')
|
||||
if include_traceback:
|
||||
raise
|
||||
exit_status = ExitStatus.ERROR
|
||||
exit_status = ExitStatus.ERROR_CTRL_C
|
||||
except SystemExit as e:
|
||||
if e.code != ExitStatus.OK:
|
||||
env.stderr.write('\n')
|
||||
|
@ -1,9 +1,25 @@
|
||||
import mock
|
||||
|
||||
from httpie import ExitStatus
|
||||
from utils import TestEnvironment, http, HTTP_OK
|
||||
|
||||
|
||||
def test_keyboard_interrupt_during_arg_parsing_exit_status(httpbin):
|
||||
with mock.patch('httpie.cli.parser.parse_args',
|
||||
side_effect=KeyboardInterrupt()):
|
||||
r = http('GET', httpbin.url + '/status/200', error_exit_ok=True)
|
||||
assert r.exit_status == ExitStatus.ERROR_CTRL_C
|
||||
|
||||
|
||||
def test_keyboard_interrupt_in_program_exit_status(httpbin):
|
||||
with mock.patch('httpie.core.program',
|
||||
side_effect=KeyboardInterrupt()):
|
||||
r = http('GET', httpbin.url + '/status/200', error_exit_ok=True)
|
||||
assert r.exit_status == ExitStatus.ERROR_CTRL_C
|
||||
|
||||
|
||||
def test_ok_response_exits_0(httpbin):
|
||||
r = http('GET', httpbin.url + '/status/200')
|
||||
r = http('GET', httpbin.url + '/get')
|
||||
assert HTTP_OK in r
|
||||
assert r.exit_status == ExitStatus.OK
|
||||
|
||||
|
@ -192,7 +192,7 @@ def http(*args, **kwargs):
|
||||
args_with_config_defaults = args + env.config.default_options
|
||||
add_to_args = []
|
||||
if '--debug' not in args_with_config_defaults:
|
||||
if '--traceback' not in args_with_config_defaults:
|
||||
if not error_exit_ok and '--traceback' not in args_with_config_defaults:
|
||||
add_to_args.append('--traceback')
|
||||
if not any('--timeout' in arg for arg in args_with_config_defaults):
|
||||
add_to_args.append('--timeout=3')
|
||||
|
Loading…
Reference in New Issue
Block a user