From d0c0dc0e71d666b162a7ac80849c6be69e47d57d Mon Sep 17 00:00:00 2001 From: Oluwatosin Adewale Date: Thu, 31 Jan 2019 21:55:17 -0800 Subject: [PATCH 1/2] Azhelpgen can now handle new help objects. --- scripts/refdoc/azhelpgen/azhelpgen.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/refdoc/azhelpgen/azhelpgen.py b/scripts/refdoc/azhelpgen/azhelpgen.py index 693a13b013d..71cf66a0dad 100644 --- a/scripts/refdoc/azhelpgen/azhelpgen.py +++ b/scripts/refdoc/azhelpgen/azhelpgen.py @@ -124,14 +124,14 @@ 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) + yield '{}.. cliexample:: {}'.format(INDENT, e.short_summary) yield '' - yield DOUBLEINDENT + e.text.replace("\\", "\\\\") + yield DOUBLEINDENT + e.command.replace("\\", "\\\\") yield '' def run(self): @@ -164,3 +164,15 @@ 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 From efdd1db3df0f69f422422e634f90edb42a74151b Mon Sep 17 00:00:00 2001 From: Oluwatosin Adewale Date: Fri, 1 Feb 2019 10:18:46 -0800 Subject: [PATCH 2/2] Updated examples to be backwards compatible. --- scripts/refdoc/azhelpgen/azhelpgen.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/refdoc/azhelpgen/azhelpgen.py b/scripts/refdoc/azhelpgen/azhelpgen.py index 71cf66a0dad..9daadc7d1e5 100644 --- a/scripts/refdoc/azhelpgen/azhelpgen.py +++ b/scripts/refdoc/azhelpgen/azhelpgen.py @@ -129,9 +129,10 @@ def make_rst(self): yield '' if len(help_file.examples) > 0: for e in help_file.examples: - yield '{}.. cliexample:: {}'.format(INDENT, e.short_summary) + fields = _get_example_fields(e) + yield '{}.. cliexample:: {}'.format(INDENT, fields['summary']) yield '' - yield DOUBLEINDENT + e.command.replace("\\", "\\\\") + yield DOUBLEINDENT + fields['command'].replace("\\", "\\\\") yield '' def run(self): @@ -176,3 +177,14 @@ def _get_populator_commands(param): 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 \ No newline at end of file