Commit f66cbf59 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

handle bool type from command line

parent f2be7d7a
......@@ -115,10 +115,7 @@ if __name__ == '__main__':
# create the subparser for each applications
sub_parser = subparsers.add_parser(instance.name, help=instance.description)
for param in instance.parameters:
sub_parser.add_argument(param.flag, type=param.type, help=param.help,
required=param.required, dest=param.name,
metavar=param.metavar, default=param.default,
action=param.action, choices=param.choices)
sub_parser.add_argument(param.flag, **param.export_to_argparse())
sub_parser.set_defaults(cmd_object=instance.__class__.__name__)
args = vars(parser.parse_args())
......
......@@ -52,9 +52,24 @@ class Parameter(object):
self.default = today.strftime('%d/%m/%Y')
self.action = action
if self.action == "append":
if self.type == types.BooleanType and str(self.default).lower() in ("false", "f", "0"):
self.action = "store_false"
self.default = True
elif self.type == types.BooleanType:
self.action = "store_true"
self.default = False
elif self.action == "append":
self.default = []
def export_to_argparse(self):
if self.type == types.BooleanType:
return {"help": self.help, "required": self.required, "dest": self.name,
"default": self.default, "action": self.action}
else:
return {"type": self.type, "help": self.help, "required": self.required,
"dest": self.name, "metavar": self.metavar, "default": self.default,
"action": self.action, "choices": self.choices}
def get_type(self):
return self.type.__name__
......
......@@ -206,6 +206,9 @@ class Workflow(threading.Thread):
extended_args[param.name] = date(args[param.name])
else:
extended_args[param.name] = args[param.name]
# if it's a boolean
elif param.type == types.BooleanType:
extended_args[param.name] = args[param.name] in ['true', '1', 't', 'y', 'yes']
else:
extended_args[param.name] = args[param.name]
# otherwise use the default
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment