added ability to parse bool and list from argparse

pull/31/head
yhtiyar 2021-12-11 01:41:21 +03:00
rodzic 77288ea543
commit 07e6aa5332
2 zmienionych plików z 29 dodań i 5 usunięć

Wyświetl plik

@ -226,7 +226,7 @@ def function_spec(function_abi: Dict[str, Any]) -> Dict[str, Dict[str, Any]]:
item_type = python_type(item["type"])[0]
item_cli_type = None
if item_type in {"int", "bool"}:
if item_type in {"int", "str"}:
item_cli_type = item_type
input_spec: Dict[str, Any] = {
@ -235,6 +235,7 @@ def function_spec(function_abi: Dict[str, Any]) -> Dict[str, Dict[str, Any]]:
"cli": item_cli_name,
"args": item_args_name,
"type": item_type,
"raw_type": item["type"],
"cli_type": item_cli_type,
}

Wyświetl plik

@ -560,12 +560,35 @@ def generate_cli_generator(
keyword=cst.Name(value="required"),
value=cst.Name(value="True"),
),
]
if param["type"] is not None:
cst.Arg(
keyword=cst.Name(value="type"),
value=cst.Name(param["type"]),
keyword=cst.Name(value="help"),
value=cst.SimpleString(value=f'u"Type: {param["raw_type"]}"'),
),
]
if param["cli_type"] is not None:
call_args.append(
cst.Arg(
keyword=cst.Name(value="type"),
value=cst.Name(param["cli_type"]),
),
)
if param["type"] == "List":
call_args.append(
cst.Arg(
keyword=cst.Name(value="nargs"),
value=cst.SimpleString(value=f'u"+"'),
),
)
elif param["type"] == "bool":
call_args.append(
cst.Arg(
keyword=cst.Name(value="type"),
value=cst.parse_expression(
"lambda x: (str(x).lower() == 'true')"
),
),
)
add_argument_call = cst.Call(
func=cst.Attribute(