Skip to content

Commit 1e15b99

Browse files
committed
added method to take into account the order of positional command line args
1 parent 63d96be commit 1e15b99

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def generate_boutiques_descriptor(
140140

141141
tool_desc['tags'] = desc_tags
142142

143+
# Check for positional arguments and reorder command line args if necessary
144+
tool_desc['command-line'] = reorder_cmd_line_args(tool_desc['command-line'], interface, ignore_inputs)
145+
143146
# Remove the extra space at the end of the command line
144147
tool_desc['command-line'] = tool_desc['command-line'].strip()
145148

@@ -505,3 +508,31 @@ def generate_custom_inputs(desc_inputs):
505508
for value in desc_input['value-choices']:
506509
custom_input_dicts.append({desc_input['id']: value})
507510
return custom_input_dicts
511+
512+
513+
def reorder_cmd_line_args(cmd_line, interface, ignore_inputs=None):
514+
'''
515+
Generates a new command line with the positional arguments in the correct order
516+
'''
517+
interface_name = cmd_line.split()[0]
518+
positional_arg_dict = {}
519+
positional_args = []
520+
non_positional_args = []
521+
522+
for name, spec in sorted(interface.inputs.traits(transient=None).items()):
523+
if ignore_inputs is not None and name in ignore_inputs:
524+
continue
525+
value_key = "[" + name.upper() + "]"
526+
if spec.position is not None:
527+
positional_arg_dict[spec.position] = value_key
528+
else:
529+
non_positional_args.append(value_key)
530+
531+
last_arg = None
532+
for item in sorted(positional_arg_dict.items()):
533+
if item[0] == -1:
534+
last_arg = item[1]
535+
continue
536+
positional_args.append(item[1])
537+
538+
return interface_name + " " + " ".join(positional_args) + " " + ((last_arg + " ") if last_arg else "") + " ".join(non_positional_args)

0 commit comments

Comments
 (0)