kopia lustrzana https://github.com/bugout-dev/moonworm
added ability to parse bool and list from argparse
rodzic
77288ea543
commit
07e6aa5332
|
@ -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_type = python_type(item["type"])[0]
|
||||||
|
|
||||||
item_cli_type = None
|
item_cli_type = None
|
||||||
if item_type in {"int", "bool"}:
|
if item_type in {"int", "str"}:
|
||||||
item_cli_type = item_type
|
item_cli_type = item_type
|
||||||
|
|
||||||
input_spec: Dict[str, Any] = {
|
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,
|
"cli": item_cli_name,
|
||||||
"args": item_args_name,
|
"args": item_args_name,
|
||||||
"type": item_type,
|
"type": item_type,
|
||||||
|
"raw_type": item["type"],
|
||||||
"cli_type": item_cli_type,
|
"cli_type": item_cli_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -560,12 +560,35 @@ def generate_cli_generator(
|
||||||
keyword=cst.Name(value="required"),
|
keyword=cst.Name(value="required"),
|
||||||
value=cst.Name(value="True"),
|
value=cst.Name(value="True"),
|
||||||
),
|
),
|
||||||
]
|
|
||||||
if param["type"] is not None:
|
|
||||||
cst.Arg(
|
cst.Arg(
|
||||||
keyword=cst.Name(value="type"),
|
keyword=cst.Name(value="help"),
|
||||||
value=cst.Name(param["type"]),
|
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(
|
add_argument_call = cst.Call(
|
||||||
func=cst.Attribute(
|
func=cst.Attribute(
|
||||||
|
|
Ładowanie…
Reference in New Issue