Skip to content
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
30 changes: 27 additions & 3 deletions scripts/refdoc/azhelpgen/azhelpgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ def make_rst(self):
pass
yield '{}:default: {}'.format(DOUBLEINDENT, arg.default)
if arg.value_sources:
yield '{}:source: {}'.format(DOUBLEINDENT, ', '.join(arg.value_sources))
yield '{}:source: {}'.format(DOUBLEINDENT, ', '.join(_get_populator_commands(arg)))
yield ''
yield ''
if len(help_file.examples) > 0:
for e in help_file.examples:
yield '{}.. cliexample:: {}'.format(INDENT, e.name)
fields = _get_example_fields(e)
yield '{}.. cliexample:: {}'.format(INDENT, fields['summary'])
yield ''
yield DOUBLEINDENT + e.text.replace("\\", "\\\\")
yield DOUBLEINDENT + fields['command'].replace("\\", "\\\\")
yield ''

def run(self):
Expand Down Expand Up @@ -164,3 +165,26 @@ def _is_group(parser):

def _get_parser_name(s):
return (s._prog_prefix if hasattr(s, '_prog_prefix') else s.prog)[3:]


def _get_populator_commands(param):
commands = []
for value_source in param.value_sources:
try:
commands.append(value_source["link"]["command"])
except TypeError: # old value_sources are strings
commands.append(value_source)
except KeyError: # new value_sources are dicts
continue
return commands

def _get_example_fields(ex):
res = {}
try:
res['summary'] = ex.short_summary
res['command'] = ex.command
except AttributeError:
res['summary'] = ex.name
res['command'] = ex.text

return res