Skip to content

Commit f540db9

Browse files
committed
Merge pull request #1167 from chrisfilo/enh/nipype_cmd_multipath
Added support for lists of files as command line inputs.
2 parents 1360492 + 1322332 commit f540db9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

nipype/utils/nipype_cmd.py

Lines changed: 9 additions & 3 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
5+
from nipype.interfaces.base import Interface, InputMultiPath
66
from nipype.utils.misc import str2bool
77

88
def listClasses(module=None):
@@ -23,11 +23,17 @@ def add_options(parser=None, module=None, function=None):
2323
inputs = interface.input_spec()
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:]
26+
args = {}
27+
2628
if hasattr(spec, "mandatory") and spec.mandatory:
27-
parser.add_argument(name, help=desc)
29+
if spec.is_trait_type(InputMultiPath):
30+
args["nargs"]="+"
31+
parser.add_argument(name, help=desc, **args)
2832
else:
33+
if spec.is_trait_type(InputMultiPath):
34+
args["nargs"]="*"
2935
parser.add_argument("--%s"%name, dest=name,
30-
help=desc)
36+
help=desc, **args)
3137
return parser, interface
3238

3339
def run_instance(interface, options):

nipype/utils/tests/test_cmd.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@ def test_run_4d_realign_without_arguments(self):
8383

8484
self.assertEqual(stderr.getvalue(),
8585
"""usage: nipype_cmd nipype.interfaces.nipy FmriRealign4d [-h]
86-
[--between_loops BETWEEN_LOOPS]
86+
[--between_loops [BETWEEN_LOOPS [BETWEEN_LOOPS ...]]]
8787
[--ignore_exception IGNORE_EXCEPTION]
88-
[--loops LOOPS]
88+
[--loops [LOOPS [LOOPS ...]]]
8989
[--slice_order SLICE_ORDER]
90-
[--speedup SPEEDUP]
90+
[--speedup [SPEEDUP [SPEEDUP ...]]]
9191
[--start START]
9292
[--time_interp TIME_INTERP]
9393
[--tr_slices TR_SLICES]
94-
in_file tr
94+
in_file [in_file ...]
95+
tr
9596
nipype_cmd nipype.interfaces.nipy FmriRealign4d: error: too few arguments
9697
""")
9798
self.assertEqual(stdout.getvalue(), '')

0 commit comments

Comments
 (0)