diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 3c9b9125..5eea5b13 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -10,12 +10,12 @@ This project adheres to `Semantic Versioning `_.
-------------------------
* Fixed built-in plugins-related circular imports (`#925`_).
-* Added ``--format-options`` to allow disabling sorting, etc. (`#128`_)
-* Added ``--unsorted`` shortcut to set all sorting-related ``--format-options`` to ``false``. (`#128`_)
* Added ``--ciphers`` to allow configuring OpenSSL ciphers (`#870`_).
* Added support for ``$XDG_CONFIG_HOME`` (`#920`_).
* Added support for custom content types for uploaded files (`#668`_).
* Added support for ``Set-Cookie``-triggered cookie expiration (`#853`_).
+* Added ``--format-options`` to allow disabling sorting, etc. (`#128`_)
+* Added ``--sorted`` and ``--unsorted`` shortcuts for (un)setting all sorting-related ``--format-options``. (`#128`_)
* Added ``netrc`` support for auth plugins.
Enabled for ``--auth-type=basic`` and ``digest``, 3rd parties may opt in (`#718`_, `#719`_, `#852`_, `#934`_).
diff --git a/httpie/cli/constants.py b/httpie/cli/constants.py
index 6305588c..c75fafde 100644
--- a/httpie/cli/constants.py
+++ b/httpie/cli/constants.py
@@ -91,10 +91,13 @@ DEFAULT_FORMAT_OPTIONS = [
'json.indent:4',
'json.sort_keys:true',
]
-UNSORTED_FORMAT_OPTIONS = [
- 'headers.sort:false',
- 'json.sort_keys:false',
+SORTED_FORMAT_OPTIONS = [
+ 'headers.sort:true',
+ 'json.sort_keys:true',
]
+SORTED_FORMAT_OPTIONS_STRING = ','.join(SORTED_FORMAT_OPTIONS)
+UNSORTED_FORMAT_OPTIONS_STRING = ','.join(
+ option.replace('true', 'false') for option in SORTED_FORMAT_OPTIONS)
# Defaults
OUTPUT_OPTIONS_DEFAULT = OUT_RESP_HEAD + OUT_RESP_BODY
diff --git a/httpie/cli/definition.py b/httpie/cli/definition.py
index 569b9891..10fcbf58 100644
--- a/httpie/cli/definition.py
+++ b/httpie/cli/definition.py
@@ -1,7 +1,7 @@
-"""
+'''
CLI arguments definition.
-"""
+'''
from argparse import (FileType, OPTIONAL, SUPPRESS, ZERO_OR_MORE)
from textwrap import dedent, wrap
@@ -15,7 +15,8 @@ from httpie.cli.constants import (
DEFAULT_FORMAT_OPTIONS, OUTPUT_OPTIONS,
OUTPUT_OPTIONS_DEFAULT, OUT_REQ_BODY, OUT_REQ_HEAD,
OUT_RESP_BODY, OUT_RESP_HEAD, PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY,
- SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_PROXY, UNSORTED_FORMAT_OPTIONS,
+ SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_PROXY, SORTED_FORMAT_OPTIONS_STRING,
+ UNSORTED_FORMAT_OPTIONS_STRING,
)
from httpie.output.formatters.colors import (
AUTO_STYLE, AVAILABLE_STYLES, DEFAULT_STYLE,
@@ -29,7 +30,7 @@ from httpie.ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS
parser = HTTPieArgumentParser(
prog='http',
description='%s ' % __doc__.strip(),
- epilog=dedent("""
+ epilog=dedent('''
For every --OPTION there is also a --no-OPTION that reverts OPTION
to its default value.
@@ -37,7 +38,7 @@ parser = HTTPieArgumentParser(
https://github.com/jakubroztocil/httpie/issues
- """),
+ '''),
)
#######################################################################
@@ -46,18 +47,18 @@ parser = HTTPieArgumentParser(
positional = parser.add_argument_group(
title='Positional Arguments',
- description=dedent("""
+ description=dedent('''
These arguments come after any flags and in the order they are listed here.
Only URL is required.
- """)
+ ''')
)
positional.add_argument(
dest='method',
metavar='METHOD',
nargs=OPTIONAL,
default=None,
- help="""
+ help='''
The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).
This argument can be omitted in which case HTTPie will use POST if there
@@ -66,12 +67,12 @@ positional.add_argument(
$ http example.org # => GET
$ http example.org hello=world # => POST
- """
+ '''
)
positional.add_argument(
dest='url',
metavar='URL',
- help="""
+ help='''
The scheme defaults to 'http://' if the URL does not include one.
(You can override this with: --default-scheme=https)
@@ -80,7 +81,7 @@ positional.add_argument(
$ http :3000 # => http://localhost:3000
$ http :/foo # => http://localhost/foo
- """
+ '''
)
positional.add_argument(
dest='request_items',
@@ -88,7 +89,7 @@ positional.add_argument(
nargs=ZERO_OR_MORE,
default=None,
type=KeyValueArgType(*SEPARATOR_GROUP_ALL_ITEMS),
- help=r"""
+ help=r'''
Optional key-value pairs to be included in the request. The separator used
determines the type:
@@ -126,7 +127,7 @@ positional.add_argument(
field-name-with\:colon=value
- """
+ '''
)
#######################################################################
@@ -141,24 +142,24 @@ content_type = parser.add_argument_group(
content_type.add_argument(
'--json', '-j',
action='store_true',
- help="""
+ help='''
(default) Data items from the command line are serialized as a JSON object.
The Content-Type and Accept headers are set to application/json
(if not specified).
- """
+ '''
)
content_type.add_argument(
'--form', '-f',
action='store_true',
- help="""
+ help='''
Data items from the command line are serialized as form fields.
The Content-Type is set to application/x-www-form-urlencoded (if not
specified). The presence of any file fields results in a
multipart/form-data request.
- """
+ '''
)
#######################################################################
@@ -174,14 +175,14 @@ content_processing.add_argument(
'--compress', '-x',
action='count',
default=0,
- help="""
+ help='''
Content compressed (encoded) with Deflate algorithm.
The Content-Encoding header is set to deflate.
Compression is skipped if it appears that compression ratio is
negative. Compression can be forced by repeating the argument.
- """
+ '''
)
#######################################################################
@@ -195,12 +196,12 @@ output_processing.add_argument(
dest='prettify',
default=PRETTY_STDOUT_TTY_ONLY,
choices=sorted(PRETTY_MAP.keys()),
- help="""
+ help='''
Controls output processing. The value can be "none" to not prettify
the output (default for redirected output), "all" to apply both colors
and formatting (default for terminal output), "colors", or "format".
- """
+ '''
)
output_processing.add_argument(
'--style', '-s',
@@ -208,7 +209,7 @@ output_processing.add_argument(
metavar='STYLE',
default=DEFAULT_STYLE,
choices=AVAILABLE_STYLES,
- help="""
+ help='''
Output coloring style (default is "{default}"). It can be One of:
{available_styles}
@@ -219,7 +220,7 @@ output_processing.add_argument(
$TERM environment variable is set to "xterm-256color" or similar
(e.g., via `export TERM=xterm-256color' in your ~/.bashrc).
- """.format(
+ '''.format(
default=DEFAULT_STYLE,
available_styles='\n'.join(
'{0}{1}'.format(8 * ' ', line.strip())
@@ -228,22 +229,47 @@ output_processing.add_argument(
auto_style=AUTO_STYLE,
)
)
+_sorted_kwargs = {
+ 'action': 'append_const',
+ 'const': SORTED_FORMAT_OPTIONS_STRING,
+ 'dest': 'format_options'
+}
+_unsorted_kwargs = {
+ 'action': 'append_const',
+ 'const': UNSORTED_FORMAT_OPTIONS_STRING,
+ 'dest': 'format_options'
+}
+# The closest approx. of the documented resetting to default via --no-