2.5. 附加参数#
有时,一些工具需要额外的命令行选项,但我们无法让它们与 (CWL) 输入参数一一对应。
本例中,我们将包装 Java 编译器,将 java 源文件编译为类 (class) 文件。 默认情况下,“javac” 将在源文件所在目录中创建类文件。 然而,CWL 输入文件(及其所在目录)可能是只读的,因此我们需要令 “javac” 将类文件写入指定的输出目录。
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool
label: Example trivial wrapper for Java 9 compiler
hints:
DockerRequirement:
dockerPull: openjdk:9.0.1-11-slim
baseCommand: javac
arguments: ["-d", $(runtime.outdir)]
inputs:
src:
type: File
inputBinding:
position: 1
outputs:
classfile:
type: File
outputBinding:
glob: "*.class"
src:
class: File
path: Hello.java
接下来,创建一个示例 Java 文件,用来让命令行工具处理它。
$ echo "public class Hello {}" > Hello.java
现在,将刚才创建的工具描述和输入对象通过命令行传递给 cwltool
:
$ cwltool arguments.cwl arguments-job.yml
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.1.20240508115724
INFO Resolved 'arguments.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/additional-arguments-and-parameters/arguments.cwl'
ERROR Workflow error, try again with --debug for more information:
Docker is not available for this tool, try --no-container to disable Docker, or install a user space Docker replacement like uDocker with --user-space-docker-cmd.: docker executable is not available
此处我们使用 arguments
字段,给命令行添加一个与任何具体输入参数都无关的附加参数。
arguments: ["-d", $(runtime.outdir)]
此示例用到了运行时 (runtime) 参数,它们提供的是工具实际执行时的硬件或软件环境信息。 $(runtime.outdir)
参数是指定输出目录的路径。其他运行时参数还有 $(runtime.tmpdir)
、$(runtime.ram)
、$(runtime.cores)
、$(runtime.outdirSize)
, 以及 $(runtime.tmpdirSize)
等,详见 CWL 规约的 Runtime Environment(运行环境)部分。