1
0
mirror of https://github.com/httpie/cli.git synced 2025-02-13 13:18:45 +02:00

Renamed --allow-redirects to --follow.

This commit is contained in:
Jakub Roztocil 2012-09-07 11:58:39 +02:00
parent 9338aadd75
commit da0eb7db79
5 changed files with 15 additions and 12 deletions

View File

@ -858,7 +858,7 @@ Scripting
When using HTTPie from **shell scripts**, it can be handy to set the When using HTTPie from **shell scripts**, it can be handy to set the
``--check-status`` flag. It instructs HTTPie to exit with an error if the ``--check-status`` flag. It instructs HTTPie to exit with an error if the
HTTP status is one of ``3xx``, ``4xx``, or ``5xx``. The exit status will HTTP status is one of ``3xx``, ``4xx``, or ``5xx``. The exit status will
be ``3`` (unless ``--allow-redirects`` is set), ``4``, or ``5``, be ``3`` (unless ``--follow`` is set), ``4``, or ``5``,
respectively. Also, the ``--timeout`` option allows to overwrite the default respectively. Also, the ``--timeout`` option allows to overwrite the default
30s timeout: 30s timeout:
@ -993,6 +993,7 @@ Changelog
* `0.2.8-alpha`_ * `0.2.8-alpha`_
* Added persistent session support. * Added persistent session support.
* Renamed ``--allow-redirects`` to ``--follow``.
* Improved the usability of ``http --help``. * Improved the usability of ``http --help``.
* Fixed installation on Windows with Python 3. * Fixed installation on Windows with Python 3.
* Fixed colorized output on Windows with Python 3. * Fixed colorized output on Windows with Python 3.

View File

@ -3,7 +3,7 @@
NOTE: the CLI interface may change before reaching v1.0. NOTE: the CLI interface may change before reaching v1.0.
""" """
from argparse import FileType, OPTIONAL, SUPPRESS from argparse import FileType, OPTIONAL, ZERO_OR_MORE, SUPPRESS
from requests.compat import is_windows from requests.compat import is_windows
@ -63,8 +63,8 @@ positional.add_argument(
''') ''')
) )
positional.add_argument( positional.add_argument(
'items', nargs='*', 'items', metavar='REQUEST ITEM',
metavar='REQUEST ITEM', nargs=ZERO_OR_MORE,
type=KeyValueArgType(*SEP_GROUP_ITEMS), type=KeyValueArgType(*SEP_GROUP_ITEMS),
help=_(''' help=_('''
A key-value pair whose type is defined by the A key-value pair whose type is defined by the
@ -85,7 +85,9 @@ positional.add_argument(
content_type = parser.add_argument_group( content_type = parser.add_argument_group(
title='Predefined content types', title='Predefined content types',
description=None).add_mutually_exclusive_group(required=False) description=None
).add_mutually_exclusive_group(required=False)
content_type.add_argument( content_type.add_argument(
'--json', '-j', action='store_true', '--json', '-j', action='store_true',
help=_(''' help=_('''
@ -271,7 +273,7 @@ network.add_argument(
''') ''')
) )
network.add_argument( network.add_argument(
'--allow-redirects', default=False, action='store_true', '--follow', default=False, action='store_true',
help=_(''' help=_('''
Set this flag if full redirects are allowed Set this flag if full redirects are allowed
(e.g. re-POST-ing of data at new ``Location``) (e.g. re-POST-ing of data at new ``Location``)
@ -306,7 +308,7 @@ network.add_argument(
When the server replies with a 4xx (Client Error) or 5xx When the server replies with a 4xx (Client Error) or 5xx
(Server Error) status code, HTTPie exits with 4 or 5 respectively. (Server Error) status code, HTTPie exits with 4 or 5 respectively.
If the response is a 3xx (Redirect) and --allow-redirects If the response is a 3xx (Redirect) and --follow
hasn't been set, then the exit status is 3. hasn't been set, then the exit status is 3.
Also an error message is written to stderr if stdout is redirected. Also an error message is written to stderr if stdout is redirected.

View File

@ -72,7 +72,7 @@ def get_requests_kwargs(args):
'auth': credentials, 'auth': credentials,
'proxies': dict((p.key, p.value) for p in args.proxy), 'proxies': dict((p.key, p.value) for p in args.proxy),
'files': args.files, 'files': args.files,
'allow_redirects': args.allow_redirects, 'allow_redirects': args.follow,
'params': args.params, 'params': args.params,
'config': { 'config': {
'base_headers': base_headers 'base_headers': base_headers

View File

@ -27,9 +27,9 @@ from .config import CONFIG_DIR
from . import EXIT from . import EXIT
def get_exist_status(code, allow_redirects=False): def get_exist_status(code, follow=False):
"""Translate HTTP status code to exit status.""" """Translate HTTP status code to exit status."""
if 300 <= code <= 399 and not allow_redirects: if 300 <= code <= 399 and not follow:
# Redirect # Redirect
return EXIT.ERROR_HTTP_3XX return EXIT.ERROR_HTTP_3XX
elif 400 <= code <= 499: elif 400 <= code <= 499:
@ -78,7 +78,7 @@ def main(args=sys.argv[1:], env=Environment()):
if args.check_status: if args.check_status:
status = get_exist_status(response.status_code, status = get_exist_status(response.status_code,
args.allow_redirects) args.follow)
if status and not env.stdout_isatty: if status and not env.stdout_isatty:
error('%s %s', response.raw.status, response.raw.reason) error('%s %s', response.raw.status, response.raw.reason)

View File

@ -888,7 +888,7 @@ class ExitStatusTest(BaseTestCase):
def test_3xx_check_status_redirects_allowed_exits_0(self): def test_3xx_check_status_redirects_allowed_exits_0(self):
r = http( r = http(
'--check-status', '--check-status',
'--allow-redirects', '--follow',
'GET', 'GET',
httpbin('/status/301') httpbin('/status/301')
) )