summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Hoge <chris@hogepodge.com>2014-11-24 13:14:47 -0800
committerChris Hoge <chris@hogepodge.com>2014-11-24 13:18:12 -0800
commitb5f14ce99d84e7e0f5dada4f4da427bbf2472c54 (patch)
treeb3d446944663581d9abee29007e5848c071a6ed3
parent7ab33266fc34f10235467210e0cd9a9975b750ff (diff)
downloadoslo-config-b5f14ce99d84e7e0f5dada4f4da427bbf2472c54.tar.gz
Refactored help string generation
Refactored code to generate configuration help strings into its own private function. The motivation is to use the same function to generate help strings for both configuration parameters (existing functionality) and parameter groups (to be added). Partial-Bug: #1395819 Change-Id: I2c0fd50d50081c633fb50e89eb8c6a84d948f7cc
-rw-r--r--oslo/config/generator.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/oslo/config/generator.py b/oslo/config/generator.py
index e18ed1e..93594e0 100644
--- a/oslo/config/generator.py
+++ b/oslo/config/generator.py
@@ -160,6 +160,20 @@ class _OptFormatter(object):
self.output_file = output_file or sys.stdout
self.wrap_width = wrap_width
+ def _format_help(self, help_text):
+ """Format the help for a group or option to the output file.
+
+ :param help_text: The text of the help string
+ """
+ if self.wrap_width is not None and self.wrap_width > 0:
+ lines = [textwrap.fill(help_text,
+ self.wrap_width,
+ initial_indent='# ',
+ subsequent_indent='# ') + '\n']
+ else:
+ lines = ['# ' + help_text + '\n']
+ return lines
+
def format(self, opt):
"""Format a description of an option to the output file.
@@ -171,13 +185,7 @@ class _OptFormatter(object):
opt_type = self._TYPE_DESCRIPTIONS.get(type(opt), 'unknown type')
help_text = u'%s(%s)' % (opt.help + ' ' if opt.help else '', opt_type)
- if self.wrap_width is not None and self.wrap_width > 0:
- lines = [textwrap.fill(help_text,
- self.wrap_width,
- initial_indent='# ',
- subsequent_indent='# ') + '\n']
- else:
- lines = ['# ' + help_text + '\n']
+ lines = self._format_help(help_text)
for d in opt.deprecated_opts:
lines.append('# Deprecated group/name - [%s]/%s\n' %