Skip to content

Fix boolean input to argparse #77

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

Merged
merged 2 commits into from
May 5, 2016
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,13 @@ def generate_parser(toolparser, tool, namemap):
_logger.debug(u"Can't make command line argument from %s", inptype)
return None

if inptype != "boolean":
typekw = { 'type': atype }
else:
typekw = {}

toolparser.add_argument(flag + name, required=required,
help=ahelp, action=action, type=atype, default=default)
help=ahelp, action=action, default=default, **typekw)

return toolparser

Expand Down
27 changes: 27 additions & 0 deletions tests/test_toolargparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,37 @@ class ToolArgparse(unittest.TestCase):
glob: test.txt
stdout: test.txt
baseCommand: [cat]
'''

script2='''
#!/usr/bin/env cwl-runner
cwlVersion: 'cwl:draft-3'
class: CommandLineTool
inputs:
- id: bdg
type: "boolean"
outputs:
- id: output
type: File
outputBinding:
glob: foo
baseCommand:
- echo
- "ff"
stdout: foo
'''

def test_help(self):
with NamedTemporaryFile() as f:
f.write(self.script)
f.flush()
self.assertEquals(main([f.name, '--input', 'README.rst']), 0)

def test_bool(self):
with NamedTemporaryFile() as f:
f.write(self.script2)
f.flush()
try:
self.assertEquals(main([f.name, '--help']), 0)
except SystemExit as e:
self.assertEquals(e.code, 0)