11"""Command line argument parsing for cwltool."""
22
33import argparse
4+ import copy
45import os
56import urllib
67from collections .abc import MutableMapping , MutableSequence , Sequence
1011from .process import Process , shortname
1112from .resolver import ga4gh_tool_registries
1213from .software_requirements import SOFTWARE_REQUIREMENTS_ENABLED
13- from .utils import DEFAULT_TMP_PREFIX
14+ from .utils import DEFAULT_TMP_PREFIX , CWLObjectType
1415
1516
1617def arg_parser () -> argparse .ArgumentParser :
@@ -845,7 +846,7 @@ def __call__(
845846
846847
847848def add_argument (
848- toolparser : argparse .ArgumentParser ,
849+ toolparser : Union [ argparse .ArgumentParser , "argparse._ArgumentGroup" ] ,
849850 name : str ,
850851 inptype : Any ,
851852 records : list [str ],
@@ -962,14 +963,18 @@ def generate_parser(
962963 toolparser .add_argument ("job_order" , nargs = "?" , help = "Job input json file" )
963964 namemap ["job_order" ] = "job_order"
964965
965- for inp in tool .tool ["inputs" ]:
966- name = shortname (inp ["id" ])
966+ inps = copy .deepcopy (tool .tool ["inputs" ])
967+
968+ def process_input (
969+ inp : CWLObjectType , parser : Union [argparse .ArgumentParser , "argparse._ArgumentGroup" ]
970+ ) -> None :
971+ name = shortname (cast (str , inp ["id" ]))
967972 namemap [name .replace ("-" , "_" )] = name
968973 inptype = inp ["type" ]
969- description = inp .get ("doc" , inp .get ("label" , "" ))
974+ description = cast ( str , inp .get ("doc" , inp .get ("label" , "" ) ))
970975 default = inp .get ("default" , None )
971976 add_argument (
972- toolparser ,
977+ parser ,
973978 name ,
974979 inptype ,
975980 records ,
@@ -980,4 +985,27 @@ def generate_parser(
980985 base_uri ,
981986 )
982987
988+ if (groups := tool .tool .get ("http://commonwl.org/cwltool#groups" , None )) is not None :
989+ for group_name in groups .keys ():
990+ group_inputs : list [CWLObjectType ] = []
991+ for input_name in groups [group_name ]["groupMembers" ]:
992+ new_inps : list [CWLObjectType ] = []
993+ for inp in inps :
994+ if shortname (inp ["id" ]) == input_name :
995+ group_inputs .append (inp )
996+ else :
997+ new_inps .append (inp )
998+ inps = new_inps
999+
1000+ if len (group_inputs ) > 0 :
1001+ group = toolparser .add_argument_group (
1002+ title = groups [group_name ].get ("label" , group_name ),
1003+ description = groups [group_name ].get ("doc" , None ),
1004+ )
1005+ for inp in group_inputs :
1006+ process_input (inp , group )
1007+
1008+ for inp in inps :
1009+ process_input (inp , toolparser )
1010+
9831011 return toolparser
0 commit comments