Use : instead of = in `--format-options

This commit is contained in:
Jakub Roztocil 2020-05-28 12:26:06 +02:00
parent aae596d472
commit caeef2fb7c
6 changed files with 19 additions and 18 deletions

View File

@ -1403,7 +1403,7 @@ sorting, and specify a custom JSON indent size:
.. code-block:: bash
$ http --format-options headers.sort=false,json.sort_keys=false,json.indent=2 httpbin.org/get
$ http --format-options headers.sort:false,json.sort_keys:false,json.indent:2 httpbin.org/get
This is something you will typically store as one of the default options in your
`config`_ file. See ``http --help`` for all the available formatting options.

View File

@ -190,7 +190,7 @@ def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
>>> parse_format_options(
... defaults={'json': {'indent': 4, 'sort_keys': True}},
... s='json.indent=2,json.sort_keys=False',
... s='json.indent:2,json.sort_keys:False',
... )
{'json': {'indent': 2, 'sort_keys': False}}
@ -202,7 +202,7 @@ def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
options = deepcopy(defaults or {})
for option in s.split(','):
try:
path, value = option.lower().split('=')
path, value = option.lower().split(':')
section, key = path.split('.')
except ValueError:
raise argparse.ArgumentTypeError(f'invalid option {option!r}')

View File

@ -85,10 +85,10 @@ PRETTY_STDOUT_TTY_ONLY = object()
DEFAULT_FORMAT_OPTIONS = [
'headers.sort=true',
'json.format=true',
'json.indent=4',
'json.sort_keys=true',
'headers.sort:true',
'json.format:true',
'json.indent:4',
'json.sort_keys:true',
]

View File

@ -246,7 +246,7 @@ output_processing.add_argument(
You can specify multiple comma-separated options. For example, this modifies
the settings to disable the sorting of JSON keys and headers:
--format-options json.sort_keys=false,headers.sort=false
--format-options json.sort_keys:false,headers.sort:false
This is something you will typically put into your config file.

View File

@ -182,7 +182,7 @@ class TestFormatOptions:
def get_headers(sort):
return http(
'--offline', '--print=H',
'--format-options', 'headers.sort=' + sort,
'--format-options', 'headers.sort:' + sort,
'example.org', 'ZZZ:foo', 'XXX:foo',
)
@ -197,15 +197,15 @@ class TestFormatOptions:
argvalues=[
# @formatter:off
(
'json.sort_keys=true,json.indent=4',
'json.sort_keys:true,json.indent:4',
json.dumps({'a': 0, 'b': 0}, indent=4),
),
(
'json.sort_keys=false,json.indent=2',
'json.sort_keys:false,json.indent:2',
json.dumps({'b': 0, 'a': 0}, indent=2),
),
(
'json.format=false',
'json.format:false',
json.dumps({'b': 0, 'a': 0}),
),
# @formatter:on
@ -223,9 +223,9 @@ class TestFormatOptions:
argnames=['defaults', 'options_string', 'expected'],
argvalues=[
# @formatter:off
({'foo': {'bar': 1}}, 'foo.bar=2', {'foo': {'bar': 2}}),
({'foo': {'bar': True}}, 'foo.bar=false', {'foo': {'bar': False}}),
({'foo': {'bar': 'a'}}, 'foo.bar=b', {'foo': {'bar': 'b'}}),
({'foo': {'bar': 1}}, 'foo.bar:2', {'foo': {'bar': 2}}),
({'foo': {'bar': True}}, 'foo.bar:false', {'foo': {'bar': False}}),
({'foo': {'bar': 'a'}}, 'foo.bar:b', {'foo': {'bar': 'b'}}),
# @formatter:on
]
)
@ -236,9 +236,9 @@ class TestFormatOptions:
@pytest.mark.parametrize(
argnames=['options_string', 'expected_error'],
argvalues=[
('foo=2', 'invalid option'),
('foo.baz=2', 'invalid key'),
('foo.bar=false', 'expected int got bool'),
('foo:2', 'invalid option'),
('foo.baz:2', 'invalid key'),
('foo.bar:false', 'expected int got bool'),
]
)
def test_parse_format_options_errors(self, options_string, expected_error):

View File

@ -216,6 +216,7 @@ def http(
add_to_args.append('--timeout=3')
complete_args = [program_name, *add_to_args, *args]
# print(' '.join(complete_args))
def dump_stderr():
stderr.seek(0)