@@ -123,43 +123,43 @@ def from_fields(name: str,
123123 # Ugly optional workaround: https://github.com/openwdl/wdl/issues/25#issuecomment-315424063
124124 # Additional workaround for 'length(select_first({name}, [])' as length requires a non-optional array
125125 internal_pref = f'if defined({ name } ) && length(select_first([{ name } , []])) > 0 then "{ bc } " else ""'
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 )
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 )
128128
129- if array_sep and optional :
129+ elif array_sep and optional :
130130 # optional array with separator
131131 # ifdefname = f'(if defined({name}) then {name} else [])'
132- return Task .Command .CommandInput (f'~{{true="{ bc } " false="" defined({ name } )}}~{{sep= "{ array_sep } " { name } }}' , position = position )
132+ return Task .Command .CommandInput (f'~{{true="{ bc } " false="" defined({ name } )}}~{{sep( "{ array_sep } ", { name } ) }}' , position = position )
133133
134- options = []
135- if default :
134+ # build up new value from previous options
135+ value = name
136+
137+ if default is not None :
136138 val = default
137139 if isinstance (default , str ):
138140 val = f'"{ default } "'
139141 if isinstance (default , bool ):
140-
141142 val = "true" if default else "false"
142- options .append (f"default={ val } " )
143+
144+ value = f"if defined({ value } ) then { value } else { val } "
145+
143146 if array_sep :
144- options . append ( f'sep= "{ array_sep } "' )
147+ value = f'sep( "{ array_sep } ", { value } )'
145148 is_flag = true or false
146149 if is_flag :
147- options .append (f'true="{ true if true else "" } "' )
148- options .append (f'false="{ false if false else "" } "' )
149-
150- stroptions = "" .join (o + " " for o in options )
150+ value = f'if ({ value } ) then "{ true if true else "" } " else "{ false if false else "" } "'
151151
152152 prewithquotes = f'"{ bc } " + ' if bc .strip () else ""
153153 if optional and not default and not is_flag and prewithquotes :
154154 # Option 1: We apply quotes are value, Option 2: We quote whole "prefix + name" combo
155155 full_token = (
156- f"{ prewithquotes } '\" ' + { name } + '\" '"
156+ f"{ prewithquotes } '\" ' + { value } + '\" '"
157157 if (separate_value_from_prefix and prefix and prewithquotes )
158- else f"'\" ' + { prewithquotes } { name } + '\" '"
158+ else f"'\" ' + { prewithquotes } { value } + '\" '"
159159 )
160- return Task .Command .CommandInput (f'~{{{ stroptions } if defined({ name } ) then ({ full_token } ) else ""}}' , position = position )
160+ return Task .Command .CommandInput (f'~{{if defined({ value } ) then ({ full_token } ) else ""}}' , position = position )
161161 else :
162- return Task .Command .CommandInput (bc + f"~{{{ stroptions } { name } }}" , position = position )
162+ return Task .Command .CommandInput (bc + f"~{{{ value } }}" , position = position )
163163
164164 def __init__ (
165165 self ,
0 commit comments