@@ -562,8 +562,12 @@ class SelectFilesInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
562
562
desc = "When matching mutliple files, return them in sorted order." )
563
563
raise_on_empty = traits .Bool (True , usedefault = True ,
564
564
desc = "Raise an exception if a template pattern matches no files." )
565
- force_lists = traits .Bool (False , usedefault = True ,
566
- desc = "Return all values as lists even when matching a single file." )
565
+ force_lists = traits .Either (traits .Bool (), traits .List (traits .Str ()),
566
+ default = False , usedefault = True ,
567
+ desc = ("Whether to return outputs as a list even when only one file "
568
+ "matches the template. Either a boolean that applies to all "
569
+ "output fields or a list of output field names to coerce to "
570
+ " a list" ))
567
571
568
572
569
573
class SelectFiles (IOBase ):
@@ -646,6 +650,10 @@ def _list_outputs(self):
646
650
info = dict ([(k , v ) for k , v in self .inputs .__dict__ .items ()
647
651
if k in self ._infields ])
648
652
653
+ force_lists = self .inputs .force_lists
654
+ if isinstance (force_lists , bool ):
655
+ force_lists = self ._outfields if force_lists else []
656
+
649
657
for field , template in self ._templates .iteritems ():
650
658
651
659
# Build the full template path
@@ -673,7 +681,7 @@ def _list_outputs(self):
673
681
filelist .sort ()
674
682
675
683
# Handle whether this must be a list or not
676
- if not self . inputs . force_lists :
684
+ if field not in force_lists :
677
685
filelist = list_to_filename (filelist )
678
686
679
687
outputs [field ] = filelist
0 commit comments