Skip to content

Commit f03dec0

Browse files
committed
added support for boolean flags
1 parent f882fd2 commit f03dec0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

nipype/utils/nipype_cmd.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import argparse
33
import inspect
44
import sys
5-
from nipype.interfaces.base import Interface, InputMultiPath
5+
from nipype.interfaces.base import Interface, InputMultiPath, traits
66
from nipype.utils.misc import str2bool
77

88
def listClasses(module=None):
@@ -24,6 +24,9 @@ def add_options(parser=None, module=None, function=None):
2424
for name, spec in sorted(interface.inputs.traits(transient=None).items()):
2525
desc = "\n".join(interface._get_trait_desc(inputs, name, spec))[len(name)+2:]
2626
args = {}
27+
28+
if spec.is_trait_type(traits.Bool):
29+
args["action"] = 'store_true'
2730

2831
if hasattr(spec, "mandatory") and spec.mandatory:
2932
if spec.is_trait_type(InputMultiPath):
@@ -43,16 +46,17 @@ def run_instance(interface, options):
4346
for input_name, _ in interface.inputs.items():
4447
if getattr(options, input_name) != None:
4548
value = getattr(options, input_name)
46-
#traits cannot cast from string to float or int
47-
try:
48-
value = float(value)
49-
except:
50-
pass
51-
#try to cast string input to boolean
52-
try:
53-
value = str2bool(value)
54-
except:
55-
pass
49+
if not isinstance(value, bool):
50+
#traits cannot cast from string to float or int
51+
try:
52+
value = float(value)
53+
except:
54+
pass
55+
#try to cast string input to boolean
56+
try:
57+
value = str2bool(value)
58+
except:
59+
pass
5660
try:
5761
setattr(interface.inputs, input_name,
5862
value)

0 commit comments

Comments
 (0)