Skip to content

Commit

Permalink
parse_doc_options is back.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Keleshev committed Apr 15, 2012
1 parent 7b13247 commit b607d98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ def argument_eval(s):
return s


def parse_doc_options(doc):
return [Option(parse='-' + s) for s in re.split('^ *-|\n *-', doc)[1:]]


def docopt(doc, args=sys.argv[1:], help=True, version=None):
docopts = [Option(parse='-' + s) for s in re.split('^ *-|\n *-', doc)[1:]]
docopts = parse_doc_options(doc)
try:
getopts, args = gnu_getopt(args,
''.join([d.short for d in docopts if d.short]),
Expand Down
11 changes: 10 additions & 1 deletion test_docopt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from docopt import (Option, Namespace, docopt, parse, Argument, VerticalBar,
Parens, Brackets, pattern, OneOrMore)
Parens, Brackets, pattern, OneOrMore, parse_doc_options)


def test_option():
Expand Down Expand Up @@ -43,6 +43,15 @@ def test_docopt():
assert docopt('-v Be verbose.', ['-v']) == (Namespace(v=True), [])


def test_parse_doc_options():
doc = """-h, --help Print help message.
-o FILE Output file.
--verbose Verbose mode."""
assert parse_doc_options(doc) == [Option('h', 'help'),
Option('o:'),
Option(None, 'verbose')]


def test_parse():

o = [Option('h'),
Expand Down

0 comments on commit b607d98

Please sign in to comment.