diff --git a/cliff/sphinxext.py b/cliff/sphinxext.py index 793def88..82497d0a 100644 --- a/cliff/sphinxext.py +++ b/cliff/sphinxext.py @@ -56,11 +56,11 @@ def _format_usage(parser): # hacked variant of the regex used by the actual argparse module. Unlike # that version, this one attempts to group long and short opts with their - # optional arguments ensuring that, for example, '---format ' + # optional arguments ensuring that, for example, '--format ' # becomes ['--format '] and not ['--format', '']. # Yes, they really do use regexes to break apart and rewrap their help # string. Don't ask me why. - part_regexp = r'\(.*?\)+|\[.*?\]+|(?:(?:-\w|--\w+)(?:\s+<\w+>)?)|\S+' + part_regexp = r'\(.*?\)+|\[.*?\]+|(?:(?:-\w|--[\w-]+)(?:\s+?)?)|\S+' opt_usage = fmt._format_actions_usage(optionals, groups) pos_usage = fmt._format_actions_usage(positionals, groups) diff --git a/cliff/tests/test_sphinxext.py b/cliff/tests/test_sphinxext.py index 95398187..a8281bd9 100644 --- a/cliff/tests/test_sphinxext.py +++ b/cliff/tests/test_sphinxext.py @@ -157,6 +157,8 @@ class TestSphinxExtension(base.TestBase): parser.add_argument('--write-to-var-log-something-or-other', action='store_true', help='a long opt to force wrapping') + parser.add_argument('--required-arg', dest='stuff', required=True, + help='a required argument') style_group = parser.add_mutually_exclusive_group(required=True) style_group.add_argument('--polite', action='store_true', help='use a polite greeting') @@ -172,6 +174,7 @@ class TestSphinxExtension(base.TestBase): [--language LANG] [--translate] [--write-to-var-log-something-or-other] + --required-arg STUFF (--polite | --profane) name @@ -187,6 +190,10 @@ class TestSphinxExtension(base.TestBase): a long opt to force wrapping + .. option:: --required-arg + + a required argument + .. option:: --polite use a polite greeting