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

Document arg groups as a single entity #17

Merged
merged 1 commit into from
Aug 29, 2013
Merged
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
25 changes: 23 additions & 2 deletions bcdoc/clidocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ def doc_subitem(self, command_name, help_command, **kwargs):

class OperationDocumentEventHandler(CLIDocumentEventHandler):

def __init__(self, help_command):
super(OperationDocumentEventHandler, self).__init__(help_command)
self._arg_groups = self._build_arg_table_groups(help_command)
self._documented_arg_groups = []

def _build_arg_table_groups(self, help_command):
arg_groups = {}
for name, arg in help_command.arg_table.items():
if arg.group_name is not None:
arg_groups.setdefault(arg.group_name, []).append(arg)
return arg_groups

def build_translation_map(self):
LOG.debug('build_translation_map')
operation = self.help_command.obj
Expand Down Expand Up @@ -268,8 +280,17 @@ def doc_options_start(self, help_command, **kwargs):
def doc_option(self, arg_name, help_command, **kwargs):
doc = help_command.doc
argument = help_command.arg_table[arg_name]
doc.write('``%s`` (%s)\n' % (argument.cli_name,
argument.cli_type_name))
if argument.group_name in self._arg_groups:
if argument.group_name in self._documented_arg_groups:
# This arg is already documented so we can move on.
return
name = ' | '.join(
['``%s``' % a.cli_name for a in
self._arg_groups[argument.group_name]])
self._documented_arg_groups.append(argument.group_name)
else:
name = '``%s``' % argument.cli_name
doc.write('%s (%s)\n' % (name, argument.cli_type_name))
doc.style.indent()
doc.include_doc_string(argument.documentation)
doc.style.dedent()
Expand Down