Skip to content

Commit b7c5383

Browse files
authored
Merge pull request #137 from common-workflow-language/kaushik-work-patch-1
Expand create file example to show how to inject expressions into bash scripts
2 parents 3cf61da + fe0c319 commit b7c5383

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

_episodes/14-runtime.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ teaching: 10
44
exercises: 0
55
questions:
66
- "How do I create required input files from input parameters at runtime?"
7+
- "How do I invoke a script rather than just a simple command line?"
8+
- "How do I make inputs available to my script?"
79
objectives:
810
- "Learn how to create files on the fly during runtime."
11+
- "Learn how to use expressions in bash scripts."
912
keypoints:
1013
- "Use `InitialWorkDirRequirement` to specify input files that need to be
1114
created during tool runtime."
1215
---
1316
Sometimes you need to create a file on the fly from input parameters,
1417
such as tools which expect to read their input configuration from a file
15-
rather than the command line parameters. To do this, use
16-
`InitialWorkDirRequirement`.
18+
rather than the command line parameters, or need a small wrapper shell script.
19+
20+
To generate such files we can use the `InitialWorkDirRequirement`.
1721

1822
*createfile.cwl*
1923

@@ -22,6 +26,12 @@ rather than the command line parameters. To do this, use
2226
~~~
2327
{: .source}
2428

29+
Any [expressions](../13-expressions/index.html) like `$(inputs.message)` are expanded by the CWL engine before creating the file; here inserting the value at the input `message`.
30+
31+
> **Tip:** The _CWL expressions_ are independent of any _shell variables_ used later during command line tool invocation. That means that any genuine need for the character `$` should be **_escaped** with `\`, for instance `\${PREFIX}` above is expanded to `${PREFIX}` in the generated file to be evaluated by the shell script instead of the CWL engine.
32+
33+
To test the above CWL tool use this job to provide the input value `message`:
34+
2535
*echo-job.yml*
2636

2737
~~~
@@ -34,22 +44,26 @@ command line:
3444

3545
~~~
3646
$ cwl-runner createfile.cwl echo-job.yml
37-
[job createfile.cwl] /home/example$ cat \
38-
example.conf > /home/example/output.txt
47+
[job createfile.cwl] /private/tmp/docker_tmphrqxxcdl$ sh \
48+
example.sh > /private/tmp/docker_tmphrqxxcdl/output.txt
49+
Could not collect memory usage, job ended before monitoring began.
3950
[job createfile.cwl] completed success
4051
{
4152
"example_out": {
4253
"location": "file:///home/example/output.txt",
4354
"basename": "output.txt",
4455
"class": "File",
45-
"checksum": "sha1$5d3f955d1bb862ec618bc2f7ca4c5fa29fa39e89",
46-
"size": 22,
56+
"checksum": "sha1$9045abe4bd04dd8ccfe50c6ff61820b784b64aa7",
57+
"size": 25,
4758
"path": "/home/example/output.txt"
4859
}
4960
}
5061
Final process status is success
5162
$ cat output.txt
52-
CONFIGVAR=Hello world!
63+
Message is: Hello world!
5364
~~~
5465
{: .output}
66+
67+
68+
5569
{% include links.md %}

_includes/cwl/14-runtime/createfile.cwl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#!/usr/bin/env cwl-runner
2-
31
class: CommandLineTool
42
cwlVersion: v1.0
5-
baseCommand: ["cat", "example.conf"]
3+
baseCommand: ["sh", "example.sh"]
64

75
requirements:
86
InitialWorkDirRequirement:
97
listing:
10-
- entryname: example.conf
11-
entry: |
12-
CONFIGVAR=$(inputs.message)
8+
- entryname: example.sh
9+
entry: |-
10+
PREFIX='Message is:'
11+
MSG="\${PREFIX} $(inputs.message)"
12+
echo \${MSG}
1313

1414
inputs:
1515
message: string

_includes/cwl/conformance-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@
158158
output:
159159
example_out:
160160
class: File
161-
checksum: sha1$5509385b089c054ac9f9890dccef666eda7eb79d
161+
checksum: sha1$9045abe4bd04dd8ccfe50c6ff61820b784b64aa7
162162
basename: output.txt
163163
location: Any
164-
size: 23
164+
size: 25
165165

166166
# Section 15
167167
- doc: Test for section 15

0 commit comments

Comments
 (0)