Skip to content
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

An option description can be located after a new line #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docopt_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ namespace docopt {
options_end = option_description.begin() + static_cast<std::ptrdiff_t>(double_space);
}

static const std::regex pattern {"(-{1,2})?(.*?)([,= ]|$)"};
static const std::regex pattern {"(-{1,2})?(.*?)([,= \n]|$)"};
for(std::sregex_iterator i {option_description.begin(), options_end, pattern, std::regex_constants::match_not_null},
e{};
i != e;
Expand Down
20 changes: 20 additions & 0 deletions testcases.docopt
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,23 @@ other options:
"""
$ prog --baz --egg
{"--foo": false, "--baz": true, "--bar": false, "--egg": true, "--spam": false}


# An option description can be located after a new line.
r"""usage: prog [options]

options:
--foo, -f
Description on a new line.
--bar, -b
Description on a new line.
"""

$ prog --foo
{"--foo": true, "--bar": false}
$ prog --f
{"--foo": true, "--bar": false}
$ prog --bar
{"--foo": false, "--bar": true}
$ prog -b
{"--foo": false, "--bar": true}