Skip to content

Commit b4f7fd3

Browse files
IgnacioHerediaalvarolopez
authored andcommitted
feat: support bools
1 parent 43c4a6f commit b4f7fd3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

deepaas/cmd/cli.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@
4949
# Passing lists or dicts with argparse is not straight forward, so we use pass them as
5050
# string and parse them with `ast.literal_eval`
5151
# ref: https://stackoverflow.com/questions/7625786/type-dict-in-argparse-add-argument
52+
# We follow a similar approach with bools
53+
# ref: https://stackoverflow.com/a/59579733/18471590
54+
# ref: https://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python/18472142#18472142
55+
56+
def str2bool(v):
57+
return v.lower() in ("yes", "true", "t", "1")
58+
59+
5260
FIELD_TYPE_CONVERTERS = {
53-
fields.Bool: bool,
54-
fields.Boolean: bool,
61+
fields.Bool: str2bool,
62+
fields.Boolean: str2bool,
5563
fields.Date: str,
5664
fields.DateTime: str,
5765
fields.Dict: ast.literal_eval,
@@ -111,6 +119,8 @@ def _fields_to_dict(fields_in):
111119
val_help += '\nType: list, enclosed as string: "[...]"'
112120
elif val_type is fields.Dict:
113121
val_help += '\nType: dict, enclosed as string: "{...}"'
122+
elif val_type in [fields.Bool, fields.Boolean]:
123+
val_help += '\nType: bool'
114124
else:
115125
val_help += f"\nType: {param['type'].__name__}"
116126
if val_type is fields.Field:

0 commit comments

Comments
 (0)