@@ -188,7 +188,7 @@ This will be demonstrated in the next lesson
188188and is discussed in more detail in the [ YAML Guide] ( yaml-guide.md#arrays ) .
189189You can specify arrays of arrays, arrays of records, and other complex types.
190190
191- ## Advanced Inputs
191+ ## Inclusive and Exclusive Inputs
192192
193193Sometimes an underlying tool has several arguments that must be provided
194194together (they are dependent) or several arguments that cannot be provided
@@ -209,6 +209,7 @@ parameters together to describe these two conditions.
209209
210210``` {runcmd} cwltool record.cwl record-job1.yml
211211:working-directory: src/_includes/cwl/inputs/
212+ :emphasize-lines: 6-7
212213```
213214
214215In the first example, you can't provide ` itemA ` without also providing ` itemB ` .
@@ -221,15 +222,16 @@ In the first example, you can't provide `itemA` without also providing `itemB`.
221222
222223``` {runcmd} cwltool record.cwl record-job2.yml
223224:working-directory: src/_includes/cwl/inputs
225+ :emphasize-lines: 3, 9-10, 24
224226````
225227
226228```{code-block} console
227229$ cat output.txt
228230-A one -B two -C three
229231```
230232
231- In the second example, ` itemC ` and ` itemD ` are exclusive, so only ` itemC `
232- is added to the command line and ` itemD ` is ignored.
233+ In the second example, ` itemC ` and ` itemD ` are exclusive, so only the first
234+ matching item ( ` itemC ` ) is added to the command line and remaining item ( ` itemD ` ) is ignored.
233235
234236``` {literalinclude} /_includes/cwl/inputs/record-job3.yml
235237:language: yaml
@@ -239,6 +241,7 @@ is added to the command line and `itemD` is ignored.
239241
240242``` {runcmd} cwltool record.cwl record-job3.yml
241243:working-directory: src/_includes/cwl/inputs
244+ :emphasize-lines: 9-10, 24
242245````
243246
244247```{code-block} console
@@ -249,10 +252,49 @@ $ cat output.txt
249252In the third example, only ` itemD ` is provided, so it appears on the
250253command line.
251254
255+ ### Exclusive Input Parameters with Expressions
256+
257+ If you use exclusive input parameters combined with expressions, you need to be
258+ aware that the ` inputs ` JavaScript object will contain one of the exclusive
259+ input values. This means that you might need to use an ** or** boolean operator
260+ to check which values are present.
261+
262+ Let's use an example that contains an exclusive ` file_format ` input parameter
263+ that accepts ` null ` (i.e. no value provided), or any value from an enum.
264+
265+ ``` {literalinclude} /_includes/cwl/inputs/exclusive-parameter-expressions.cwl
266+ :language: cwl
267+ :caption: "`exclusive-parameter-expressions.cwl`"
268+ :name: exclusive-parameter-expressions.cwl
269+ :emphasize-lines: 7, 21-23
270+ ```
271+
272+ Note how the JavaScript expression uses the value of the exclusive input parameter
273+ without taking into consideration a ` null ` value. If you provide a valid value,
274+ such as “fasta” (one of the values of the enum), your command should execute
275+ successfully:
276+
277+ ``` {runcmd} cwltool exclusive-parameter-expressions.cwl --file_format fasta
278+ :working-directory: src/_includes/cwl/inputs
279+ ````
280+
281+ However, if you do not provide any input value, then `file_format` will be
282+ evaluated to a `null` value, which does not match the expected type for the
283+ output field (a `string`), resulting in failure when running your workflow.
284+
285+ ```{runcmd} cwltool exclusive-parameter-expressions.cwl
286+ :working-directory: src/_includes/cwl/inputs
287+ :emphasize-lines: 6-10
288+ ```
289+
290+ To correct it, you must remember to use an or operator in your JavaScript expression
291+ when using exclusive parameters, or any parameter that allows ` null ` . For example,
292+ the expression could be changed to ` $(inputs.file_format || 'auto') ` , to have
293+ a default value if none was provided in the command line or job input file.
294+
252295% TODO
253296%
254297% - Explain its fields, such as default, valueFrom, etc. - https://github.com/common-workflow-language/common-workflow-language/issues/359
255- % - Exclusive parameters https://github.com/common-workflow-language/user_guide/issues/162
256298% - Optional Inputs https://github.com/common-workflow-language/user_guide/issues/44
257299% - Several ways of defining inputs/arguments to tools and workflows - https://github.com/common-workflow-language/user_guide/issues/33
258300% - Using an input output in another input - https://github.com/common-workflow-language/user_guide/issues/90
0 commit comments