@@ -140,6 +140,9 @@ def generate_boutiques_descriptor(
140
140
141
141
tool_desc ['tags' ] = desc_tags
142
142
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
+
143
146
# Remove the extra space at the end of the command line
144
147
tool_desc ['command-line' ] = tool_desc ['command-line' ].strip ()
145
148
@@ -505,3 +508,31 @@ def generate_custom_inputs(desc_inputs):
505
508
for value in desc_input ['value-choices' ]:
506
509
custom_input_dicts .append ({desc_input ['id' ]: value })
507
510
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