2022-03-07 23:34:04 +01:00
|
|
|
from httpie.cli.options import ParserSpec, Qualifiers
|
|
|
|
|
|
|
|
|
|
|
|
def test_parser_serialization():
|
|
|
|
small_parser = ParserSpec("test_parser")
|
|
|
|
|
|
|
|
group_1 = small_parser.add_group("group_1")
|
2022-04-14 16:43:10 +02:00
|
|
|
group_1.add_argument("regular_arg", help="regular arg", short_help="short")
|
2022-03-07 23:34:04 +01:00
|
|
|
group_1.add_argument(
|
|
|
|
"variadic_arg",
|
|
|
|
metavar="META",
|
|
|
|
help=Qualifiers.SUPPRESS,
|
2022-04-14 16:43:10 +02:00
|
|
|
nargs=Qualifiers.ZERO_OR_MORE
|
2022-03-07 23:34:04 +01:00
|
|
|
)
|
|
|
|
group_1.add_argument(
|
|
|
|
"-O",
|
|
|
|
"--opt-arg",
|
|
|
|
action="lazy_choices",
|
|
|
|
getter=lambda: ["opt_1", "opt_2"],
|
2022-04-14 16:43:10 +02:00
|
|
|
help_formatter=lambda state, *, isolation_mode: ", ".join(state),
|
|
|
|
short_help="short_help",
|
2022-03-07 23:34:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
group_2 = small_parser.add_group("group_2")
|
|
|
|
group_2.add_argument("--typed", action="store_true", type=int)
|
|
|
|
|
|
|
|
definition = small_parser.finalize()
|
|
|
|
assert definition.serialize() == {
|
|
|
|
"name": "test_parser",
|
|
|
|
"description": None,
|
|
|
|
"groups": [
|
|
|
|
{
|
|
|
|
"name": "group_1",
|
|
|
|
"description": None,
|
|
|
|
"is_mutually_exclusive": False,
|
|
|
|
"args": [
|
|
|
|
{
|
|
|
|
"options": ["regular_arg"],
|
|
|
|
"description": "regular arg",
|
2022-04-14 16:43:10 +02:00
|
|
|
"short_description": "short",
|
2022-03-07 23:34:04 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"options": ["variadic_arg"],
|
|
|
|
"is_optional": True,
|
|
|
|
"is_variadic": True,
|
|
|
|
"metavar": "META",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"options": ["-O", "--opt-arg"],
|
|
|
|
"description": "opt_1, opt_2",
|
2022-04-14 16:43:10 +02:00
|
|
|
"short_description": "short_help",
|
2022-03-07 23:34:04 +01:00
|
|
|
"choices": ["opt_1", "opt_2"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "group_2",
|
|
|
|
"description": None,
|
|
|
|
"is_mutually_exclusive": False,
|
|
|
|
"args": [{"options": ["--typed"], "python_type_name": "int"}],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|