Skip to content

Commit 4fd5ca5

Browse files
authored
Merge pull request #1248 from common-workflow-language/add-doc-to-helpmsg
Add `doc` field message to the output of `--help`
2 parents 58274ef + 0730a27 commit 4fd5ca5

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

cwltool/argparser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ def generate_parser(
799799
records: List[str],
800800
input_required: bool = True,
801801
) -> argparse.ArgumentParser:
802+
toolparser.description = tool.tool.get("doc", None)
802803
toolparser.add_argument("job_order", nargs="?", help="Job input json file")
803804
namemap["job_order"] = "job_order"
804805

tests/test_toolargparse.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import argparse
12
import os
23
import sys
34
from io import BytesIO, StringIO
45
from tempfile import NamedTemporaryFile
56

67
import pytest
78

9+
from cwltool.argparser import generate_parser
10+
from cwltool.context import LoadingContext
811
import cwltool.executors
12+
from cwltool.load_tool import load_tool
913
from cwltool.main import main
1014

1115
from .util import get_data, needs_docker
@@ -162,3 +166,21 @@ def test_dont_require_inputs():
162166
finally:
163167
if script and script.name and os.path.exists(script.name):
164168
os.unlink(script.name)
169+
170+
171+
def test_argparser_with_doc():
172+
"""The `desription` field is set if `doc` field is provided."""
173+
loadingContext = LoadingContext()
174+
tool = load_tool(get_data("tests/with_doc.cwl"), loadingContext)
175+
p = argparse.ArgumentParser()
176+
parser = generate_parser(p, tool, {}, [], False)
177+
assert(parser.description is not None)
178+
179+
180+
def test_argparser_without_doc():
181+
"""The `desription` field is None if `doc` field is not provided."""
182+
loadingContext = LoadingContext()
183+
tool = load_tool(get_data("tests/without_doc.cwl"), loadingContext)
184+
p = argparse.ArgumentParser()
185+
parser = generate_parser(p, tool, {}, [], False)
186+
assert(parser.description is None)

tests/with_doc.cwl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
inputs: []
4+
baseCommand: echo
5+
outputs: []
6+
7+
doc: This should be shown in help message

tests/without_doc.cwl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
inputs: []
4+
baseCommand: echo
5+
outputs: []

0 commit comments

Comments
 (0)