Skip to content

Commit

Permalink
Document arg groups as a single entity
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed Aug 29, 2013
1 parent 420ff6c commit 556ed91
Showing 1 changed file with 23 additions and 2 deletions.
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

0 comments on commit 556ed91

Please sign in to comment.