@@ -58,84 +58,78 @@ class Command(WdlBase):
5858 class CommandArgument (WdlBase ):
5959 def __init__ (
6060 self ,
61- prefix : str = None ,
62- value : str = None ,
63- position : int = None ,
64- separate_value_from_prefix : bool = True ,
61+ value ,
62+ position = None
6563 ):
66- self .prefix : Optional [str ] = prefix
67- self .position : Optional [int ] = position
6864 self .value = value
69- self .separate = separate_value_from_prefix
65+ self .position = position
66+
67+ @staticmethod
68+ def from_fields (prefix : str = None , value : str = None , position : int = None , separate_value_from_prefix : bool = True ,):
69+ pre = prefix if prefix else ""
70+ sp = " " if separate_value_from_prefix else ""
71+ val = value if value else ""
72+ return Task .Command .CommandArgument ((pre + sp + val ).strip (), position = position )
7073
7174 def get_string (self ):
72- pre = self .prefix if self .prefix else ""
73- sp = " " if self .separate else ""
74- val = self .value if self .value else ""
75- return (pre + sp + val ).strip ()
75+ return self .value
7676
7777 class CommandInput (CommandArgument ):
7878 def __init__ (
7979 self ,
80- name : str ,
81- optional : bool = False ,
82- prefix : str = None ,
83- position : int = None ,
84- separate_value_from_prefix : bool = True ,
85- default = None ,
86- separator = None ,
87- true = None ,
88- false = None ,
89- separate_arrays = None ,
80+ value ,
81+ position = None ,
9082 ):
9183 super ().__init__ (
92- prefix = prefix ,
93- value = None ,
84+ value = value ,
9485 position = position ,
95- separate_value_from_prefix = separate_value_from_prefix ,
9686 )
97- self .name = name
98- self .optional = optional
99- self .default = default
100- self .separator = separator
101- self .true = true
102- self .false = false
103- self .separate_arrays = separate_arrays
10487
10588 @staticmethod
10689 def from_input (inp : Input , prefix : str = None , position : int = None ):
107- return Task .Command .CommandInput (
90+ return Task .Command .CommandInput . from_fields (
10891 inp .name , inp .type .optional , prefix , position
10992 )
11093
111- def get_string (self ):
94+ @staticmethod
95+ def from_fields (name : str ,
96+ optional : bool = False ,
97+ prefix : str = None ,
98+ position : int = None ,
99+ separate_value_from_prefix : bool = True ,
100+ default = None ,
101+ separator = None ,
102+ true = None ,
103+ false = None ,
104+ separate_arrays = None ):
105+
112106 name , array_sep , default , true , false = (
113- self . name ,
114- self . separator ,
115- self . default ,
116- self . true ,
117- self . false ,
107+ name ,
108+ separator ,
109+ default ,
110+ true ,
111+ false ,
118112 )
119113
120- pr = self . prefix if self . prefix else ""
121- bc = pr + (" " if self . separate and self . prefix else "" )
114+ pr = prefix if prefix else ""
115+ bc = pr + (" " if separate_value_from_prefix and prefix else "" )
122116
123- if self . separate_arrays :
124- if array_sep or default or true or false :
117+ if separate_arrays :
118+ if separate_arrays or default or true or false :
125119 print (
126120 "separate_array take preferences over: separator, default, true, false"
127121 )
128- if self . optional :
122+ if optional :
129123 # Ugly optional workaround: https://github.com/openwdl/wdl/issues/25#issuecomment-315424063
130124 # Additional workaround for 'length(select_first({name}, [])' as length requires a non-optional array
131125 internal_pref = f'if defined({ name } ) && length(select_first([{ name } , []])) > 0 then "{ bc } " else ""'
132- return f'~{{{ internal_pref } }}~{{sep=" { bc } " { name } }}'
133- return f'~{{sep=" " prefix("{ bc } ", { name } )}}'
126+ return Task . Command . CommandInput ( f'~{{{ internal_pref } }}~{{sep=" { bc } " { name } }}' , position = position )
127+ return Task . Command . CommandInput ( f'~{{sep=" " prefix("{ bc } ", { name } )}}' , position = position )
134128
135- if array_sep and self . optional :
129+ if array_sep and optional :
136130 # optional array with separator
137131 # ifdefname = f'(if defined({name}) then {name} else [])'
138- return f'~{{true="{ bc } " false="" defined({ name } )}}~{{sep="{ array_sep } " { name } }}'
132+ return Task . Command . CommandInput ( f'~{{true="{ bc } " false="" defined({ name } )}}~{{sep="{ array_sep } " { name } }}' , position = position )
139133
140134 options = []
141135 if default :
@@ -156,16 +150,16 @@ def get_string(self):
156150 stroptions = "" .join (o + " " for o in options )
157151
158152 prewithquotes = f'"{ bc } " + ' if bc .strip () else ""
159- if self . optional and not default and not is_flag and prewithquotes :
153+ if optional and not default and not is_flag and prewithquotes :
160154 # Option 1: We apply quotes are value, Option 2: We quote whole "prefix + name" combo
161155 full_token = (
162156 f"{ prewithquotes } '\" ' + { name } + '\" '"
163- if (self . separate and self . prefix and prewithquotes )
157+ if (separate_value_from_prefix and prefix and prewithquotes )
164158 else f"'\" ' + { prewithquotes } { name } + '\" '"
165159 )
166- return f'~{{{ stroptions } if defined({ name } ) then ({ full_token } ) else ""}}'
160+ return Task . Command . CommandInput ( f'~{{{ stroptions } if defined({ name } ) then ({ full_token } ) else ""}}' , position = position )
167161 else :
168- return bc + f"~{{{ stroptions } { name } }}"
162+ return Task . Command . CommandInput ( bc + f"~{{{ stroptions } { name } }}" , position = position )
169163
170164 def __init__ (
171165 self ,
0 commit comments