Skip to content

Update command-line-tool.md #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 79 additions & 5 deletions src/topics/command-line-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ The following example contains a minimal example of a CWL
command-line tool for the `echo` Linux command, using inputs and
outputs.

HOW COMMAND LINES WORK
The command line is a text interface for your computer. It’s a program that takes in commands, which it passes on to the computer’s operating system to run. From the command line, you can navigate through files and folders on your computer, just as you would with Windows Explorer on Windows or Finder on Mac OS. The difference is that the command line is fully text-based. Abbreviated as CLI, a Command Line Interface connects a user to a computer program or operating system. Through the CLI, users interact with a system or application by typing in text (commands). The command is typed on a specific line following a visual prompt from the computer. Abbreviated as CLI, a Command Line Interface connects a user to a computer program or operating system. Through the CLI, users interact with a system or application by typing in text (commands). The command is typed on a specific line following a visual prompt from the computer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this much is needed. Perhaps just a quick mention about what command line tools are and that CWL is designed to run them --- such as
"CWL is used to run analyzes consisting of command line programs. Command line programs operates from the command line or from a shell"





% TODO: Fix the missing link the graph below. We cannot have
% it here as this file is included in two other files.
% Sphinx prohibits it for the case where this could lead
Expand Down Expand Up @@ -51,19 +58,86 @@ digraph G {
:language: cwl
:caption: "`echo.cwl`"
```

```{note}

The example above uses a simplified form to define inputs and outputs.
You will learn more about in the [Inputs](../topics/inputs.md)
The example above uses a simplified form to define inputs and outputs.You will learn more about in the [Inputs](../topics/inputs.md)
and in the [Outputs](../topics/outputs.md) sections.
```

% TODO
%
% - Spaces in commands https://github.com/common-workflow-language/user_guide/issues/39
% - Arguments (tell the reader the different use cases for arguments and inputs, tell them there is a section about inputs)
DIFFERENCES BEWTWEEN ARGUMENTS AND INPUTS
Command line arguments are given to an application before it is run. For example First we give the app JavaProgram the command line arguments 30, 91, only then do we hit Enter and run it as a Java program. On the other hand, input can be given to an application during its run, because it can only ask for input after it started running. For that reason, we can print some text to the user before asking for input, indicating what input we are expecting for, etc.
The second difference is that Input can be taken any number of times. For that reason, input can be interactive - the system can take input, then respond according to it, then take more input, etc. Command line arguments are taken once, therefore can not be used to manage any interactiveness.
You will learn more about inputs in section 2.4
USE CASES FOR THE COMMAND LINE ARGUMENTS
Command line arguments are extra commands you can use when launching a program so that the program's functionality will change. Depending on the program, these arguments can be used to add more features that includes specifying a file that output should be logged to, specifying a default document to launch, or to enable features that may be a bit buggy for normal use.
A command line argument is simply anything we enter after the executable name. for example, if we launched Notepad using the command C:\Windows\System32\notepad.exe /s, then /s would be the command line argument we used.
It is important to note that you must add a space betten the program you want to run and the command line argument. For example notepad.exe/s is not a valid argument because it does not contain aspace. Instead you must add a space so it looks like notpad.exe /s.

Available primitive types are string, int, long, float, double, and null; complex types are array and record; in addition there are special types File, Directory and Any.

The following example demonstrates some input parameters with different types and appearing on the command line in different ways.

First, create a file called inp.cwl, containing the following:

inp.cwl
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
baseCommand: echo
inputs:
example_flag:
type: boolean
inputBinding:
position: 1
prefix: -f
example_string:
type: string
inputBinding:
position: 3
prefix: --example-string
example_int:
type: int
inputBinding:
position: 2
prefix: -i
separate: false
example_file:
type: File?
inputBinding:
prefix: --file=
separate: false
position: 4

outputs: []

Sometimes tools require additional command line options that don’t correspond exactly to input parameters.

In this example, we will wrap the Java compiler to compile a java source file to a class file. By default, “javac” will create the class files in the same directory as the source file. However, CWL input files (and the directories in which they appear) may be read-only, so we need to instruct “javac” to write the class file to the designated output directory instead.

arguments.cwl
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
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"

## Network Access
This indicates whether a process requires outgoing IPv4/IPv6 network access.
Expand Down