Repository: common-workflow-language/cwltool

Issue:
Creating input yaml - issue with ruamel comments.py
Hi,
I am using cwltool version 3.0.20201203173111 that came with `pip install cwl-runner`.  This might be issue with ruamel or with my workflow but here is run command and trace:

`cwltool --make-template --debug tumor_only_exome.cwl > hiv_input.yml`

traceback:
```
Traceback (most recent call last):
  File "/home/coyote/anaconda3/envs/cwl/lib/python3.6/site-packages/cwltool/main.py", line 991, in main
    make_template(tool)
  File "/home/coyote/anaconda3/envs/cwl/lib/python3.6/site-packages/cwltool/main.py", line 744, in make_template
    generate_input_template(tool),
  File "/home/coyote/anaconda3/envs/cwl/lib/python3.6/site-packages/cwltool/main.py", line 301, in generate_input_template
    template.insert(0, name, value, comment)
  File "/home/coyote/anaconda3/envs/cwl/lib/python3.6/site-packages/ruamel/yaml/comments.py", line 722, in insert
    self.yaml_add_eol_comment(comment, key=key)
  File "/home/coyote/anaconda3/envs/cwl/lib/python3.6/site-packages/ruamel/yaml/comments.py", line 295, in yaml_add_eol_comment
    if comment[0] != '#':
IndexError: string index out of range
```



Discussion:
Thank you @BJWiley233 for your report. Can you link to your `tumor_only_exome.cwl` file or upload it here?

Resolving patch:
diff --git a/cwltool/main.py b/cwltool/main.py
--- a/cwltool/main.py
+++ b/cwltool/main.py
@@ -195,13 +195,15 @@ def generate_example_input(
                 else:
                     comment = "optional"
         else:
-            example = CommentedSeq()
-            for index, entry in enumerate(inptype):
+            example, comment = generate_example_input(inptype[0], default)
+            type_names = []
+            for entry in inptype:
                 value, e_comment = generate_example_input(entry, default)
-                example.append(value)
-                example.yaml_add_eol_comment(e_comment, index)
+                if e_comment:
+                    type_names.append(e_comment)
+            comment = "one of " + ", ".join(type_names)
             if optional:
-                comment = "optional"
+                comment = f"{comment} (optional)"
     elif isinstance(inptype, Mapping) and "type" in inptype:
         if inptype["type"] == "array":
             first_item = cast(MutableSequence[CWLObjectType], inptype["items"])[0]


Test patch:
diff --git a/tests/test_make_template.py b/tests/test_make_template.py
--- a/tests/test_make_template.py
+++ b/tests/test_make_template.py
@@ -8,3 +8,21 @@
 def test_anonymous_record() -> None:
     inputs = cmap([{"type": "record", "fields": []}])
     assert main.generate_example_input(inputs, None) == ({}, "Anonymous record type.")
+
+
+def test_union() -> None:
+    """Test for --make-template for a union type."""
+    inputs = cmap(["string", "string[]"])
+    assert main.generate_example_input(inputs, None) == (
+        "a_string",
+        'one of type "string", type "string[]"',
+    )
+
+
+def test_optional_union() -> None:
+    """Test for --make-template for an optional union type."""
+    inputs = cmap(["null", "string", "string[]"])
+    assert main.generate_example_input(inputs, None) == (
+        "a_string",
+        'one of type "string", type "string[]" (optional)',
+    )