Skip to content

Commit

Permalink
make sure doc string tabs are replaced with spaces for save parsing (…
Browse files Browse the repository at this point in the history
…Issue #24)
  • Loading branch information
thasso committed Jan 20, 2014
1 parent ef1887e commit 3948610
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jip/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,8 @@ def from_docopt(cls, doc, inputs=None, outputs=None, source=None):
from jip.vendor import docopt
from jip.vendor.docopt import Required, Optional, Argument, \
OneOrMore, Command
# Fix for Issue #24. We simply make sure there are no tabs:)
doc = doc.replace("\t", " ")
inputs = [re.sub(r'^-*', '', s) for s in inputs] if inputs else []
outputs = [re.sub(r'^-*', '', s) for s in outputs] if outputs else []
opts = cls(source=source)
Expand Down
26 changes: 26 additions & 0 deletions test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,29 @@ def test_list_option_rendering():
assert render_template("${o}", o=o) == 'A B'
assert render_template("${o|join(',')}", o=o) == 'A,B'


def test_docopt_parser_with_tabs():
help_string = """\
Some Tool
Usage: tools [-t] [-i <input>...] <cmd>
Inputs:
-i, --input <input>... The input
Options:
-t Some boolean
<cmd> The command
"""
opts = Options.from_docopt(help_string)

assert len(opts) == 3 # the two + help
assert opts['input'] is not None
assert opts['input'].nargs == "*"
assert not opts['input'].required
assert opts['t'] is not None
assert opts['t'].nargs == 0
assert not opts['t'].required
assert opts['cmd'] is not None
assert opts['cmd'].nargs == 1
assert opts['cmd'].required

0 comments on commit 3948610

Please sign in to comment.