summaryrefslogtreecommitdiff
path: root/cliff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2017-08-22 10:56:15 +0100
committerStephen Finucane <sfinucan@redhat.com>2017-08-22 10:56:15 +0100
commit7a6df37f815e00c51067ab51f99fe0d5fe697fdd (patch)
treef3a9252bfc33e5753ab262261f783d3e7e74ff6a /cliff
parenta206c7464a5c28c52130ce8c831a17696609cca1 (diff)
downloadcliff-7a6df37f815e00c51067ab51f99fe0d5fe697fdd.tar.gz
sphinxext: Correct issues with usage formatting
There are two issues here stemming from required options: - If the option contains a hyphen, e.g. '--required-option', then it is split into multiple tokens - The arguments for these options are not surrounded by triangular brackets like optional options are, but these are expected Correct both issues. Change-Id: Ifc20e6936a9ce4ef4f22b2c17298d6ca552640f7
Diffstat (limited to 'cliff')
-rw-r--r--cliff/sphinxext.py4
-rw-r--r--cliff/tests/test_sphinxext.py7
2 files changed, 9 insertions, 2 deletions
diff --git a/cliff/sphinxext.py b/cliff/sphinxext.py
index 793def8..82497d0 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 <FORMAT>'
+ # optional arguments ensuring that, for example, '--format <FORMAT>'
# becomes ['--format <FORMAT>'] and not ['--format', '<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+<?\w+>?)?)|\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 9539818..a8281bd 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 <STUFF>
+
+ a required argument
+
.. option:: --polite
use a polite greeting