2
2
import argparse
3
3
import inspect
4
4
import sys
5
- from nipype .interfaces .base import Interface , InputMultiPath
5
+ from nipype .interfaces .base import Interface , InputMultiPath , traits
6
6
from nipype .utils .misc import str2bool
7
7
8
8
def listClasses (module = None ):
@@ -24,6 +24,9 @@ def add_options(parser=None, module=None, function=None):
24
24
for name , spec in sorted (interface .inputs .traits (transient = None ).items ()):
25
25
desc = "\n " .join (interface ._get_trait_desc (inputs , name , spec ))[len (name )+ 2 :]
26
26
args = {}
27
+
28
+ if spec .is_trait_type (traits .Bool ):
29
+ args ["action" ] = 'store_true'
27
30
28
31
if hasattr (spec , "mandatory" ) and spec .mandatory :
29
32
if spec .is_trait_type (InputMultiPath ):
@@ -43,16 +46,17 @@ def run_instance(interface, options):
43
46
for input_name , _ in interface .inputs .items ():
44
47
if getattr (options , input_name ) != None :
45
48
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
56
60
try :
57
61
setattr (interface .inputs , input_name ,
58
62
value )
0 commit comments