Skip to content

Commit

Permalink
Do not return empty string for hidden option in 'to_cmd'. Fixes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
emi80 committed May 6, 2014
1 parent 989b74f commit 1a15d76
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
5 changes: 1 addition & 4 deletions jip/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,10 @@ def to_cmd(self):
>>> o = Option("input", "-i", "--long", value="data.csv")
>>> assert o.to_cmd() == '-i data.csv'
Hidden options and boolean options where the value is False or None are
represented as empty string.
Options with False or None value are represented as empty string.
:returns: the cull command line representation of this option
"""
if self.hidden:
return ""
if self.nargs == 0:
if len(self.value) == 0:
return ""
Expand Down
4 changes: 4 additions & 0 deletions test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_list_string_option():
assert str(o) == "t1 t2"
assert o.to_cmd() == "-t t1 t2"

def test_hidden_option():
o = Option("output", short="-o", hidden=True, value='Test')
assert o.to_cmd() == '-o Test'


def test_argparse_parser():
from argparse import ArgumentParser
Expand Down
28 changes: 28 additions & 0 deletions test/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,31 @@ def test_tool_empty_list_options():
assert tool.options['output'].raw() == []


def test_tool_hidden_option():
@jip.tool("test")
class TestTool(object):
"""\Test tool
Usage:
test [-a <opt_a>] [-b <opt_b>] [-c] -i <input> -o <output>
Inputs:
-i, --input <input> The input
Outputs:
-o, --output <output> The output
Options:
-a <opt_a> Option a
-b <opt_b> Option b
-c Options c (a flag)
"""
def setup(self):
self.opts['output'].hidden = True

def get_command(self):
return '${options()} ${output|arg(">")}'

tool = find('test')
tool.parse_args(['-i', 'input.txt', '-a', 'A', '-c', '-o', 'output.txt'])
assert tool.get_command() == ('bash', '-a A -c -i input.txt -o output.txt >output.txt')

0 comments on commit 1a15d76

Please sign in to comment.