diff --git a/nipype/utils/nipype_cmd.py b/nipype/utils/nipype_cmd.py index b29ea8898f..749650ef51 100644 --- a/nipype/utils/nipype_cmd.py +++ b/nipype/utils/nipype_cmd.py @@ -2,7 +2,7 @@ import argparse import inspect import sys -from nipype.interfaces.base import Interface, InputMultiPath +from nipype.interfaces.base import Interface, InputMultiPath, traits from nipype.utils.misc import str2bool def listClasses(module=None): @@ -24,6 +24,9 @@ def add_options(parser=None, module=None, function=None): for name, spec in sorted(interface.inputs.traits(transient=None).items()): desc = "\n".join(interface._get_trait_desc(inputs, name, spec))[len(name)+2:] args = {} + + if spec.is_trait_type(traits.Bool): + args["action"] = 'store_true' if hasattr(spec, "mandatory") and spec.mandatory: if spec.is_trait_type(InputMultiPath): @@ -43,16 +46,17 @@ def run_instance(interface, options): for input_name, _ in interface.inputs.items(): if getattr(options, input_name) != None: value = getattr(options, input_name) - #traits cannot cast from string to float or int - try: - value = float(value) - except: - pass - #try to cast string input to boolean - try: - value = str2bool(value) - except: - pass + if not isinstance(value, bool): + #traits cannot cast from string to float or int + try: + value = float(value) + except: + pass + #try to cast string input to boolean + try: + value = str2bool(value) + except: + pass try: setattr(interface.inputs, input_name, value) diff --git a/nipype/utils/tests/test_cmd.py b/nipype/utils/tests/test_cmd.py index 3aedc87c9c..368dc7cbf8 100644 --- a/nipype/utils/tests/test_cmd.py +++ b/nipype/utils/tests/test_cmd.py @@ -88,7 +88,7 @@ def test_run_4d_realign_without_arguments(self): self.assertEqual(stderr.getvalue(), """usage: nipype_cmd nipype.interfaces.nipy FmriRealign4d [-h] [--between_loops [BETWEEN_LOOPS [BETWEEN_LOOPS ...]]] - [--ignore_exception IGNORE_EXCEPTION] + [--ignore_exception] [--loops [LOOPS [LOOPS ...]]] [--slice_order SLICE_ORDER] [--speedup [SPEEDUP [SPEEDUP ...]]] @@ -113,4 +113,4 @@ def test_run_4d_realign_help(self): self.assertTrue("Run FmriRealign4d" in stdout.getvalue()) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()