1
0
mirror of https://github.com/httpie/cli.git synced 2025-01-26 03:20:27 +02:00

Improve --format-options error messages

This commit is contained in:
Jakub Roztocil 2020-05-27 16:19:32 +02:00
parent cb51faec51
commit aae596d472

View File

@ -205,8 +205,7 @@ def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
path, value = option.lower().split('=') path, value = option.lower().split('=')
section, key = path.split('.') section, key = path.split('.')
except ValueError: except ValueError:
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(f'invalid option {option!r}')
f'--format-options: invalid option: {option!r}')
if value in value_map: if value in value_map:
parsed_value = value_map[value] parsed_value = value_map[value]
@ -223,12 +222,12 @@ def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
default_value = defaults[section][key] default_value = defaults[section][key]
except KeyError: except KeyError:
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
f'--format-options: invalid key: {path!r} in {option!r}') f'invalid key {path!r}')
default_type, parsed_type = type(default_value), type(parsed_value) default_type, parsed_type = type(default_value), type(parsed_value)
if parsed_type is not default_type: if parsed_type is not default_type:
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
'--format-options: invalid value type:' 'invalid value'
f' {value!r} in {option!r}' f' {value!r} in {option!r}'
f' (expected {default_type.__name__}' f' (expected {default_type.__name__}'
f' got {parsed_type.__name__})' f' got {parsed_type.__name__})'