From 53de7deb1ced659b8800cd3728532bbc775cdfca Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Fri, 28 Apr 2017 17:40:27 +0200 Subject: [PATCH] [autohelp] Return options as dicts instead of lists This patch updates the _format_opt method to return a dict instead of a list. This makes the RST templates easier to read and maintain. Change-Id: Ia1b494b8ec8ed1e523ebe7198bcba00594e21ac5 --- autogenerate_config_docs/autohelp.py | 12 +++++++----- .../templates/autohelp-category.rst.j2 | 12 ++++++------ .../templates/autohelp-group.rst.j2 | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/autogenerate_config_docs/autohelp.py b/autogenerate_config_docs/autohelp.py index 25e30d5..8ed0e42 100755 --- a/autogenerate_config_docs/autohelp.py +++ b/autogenerate_config_docs/autohelp.py @@ -467,11 +467,13 @@ def _format_opt(option): flags.append(('Mutable', 'This option can be changed without' ' restarting.')) - return (option.dest, - opt_type, - _sanitize_default(option), - help_text, - flags) + return { + 'name': option.dest, + 'type': opt_type, + 'default': _sanitize_default(option), + 'help': help_text, + 'flags': flags + } def write_files(package_name, options, target): diff --git a/autogenerate_config_docs/templates/autohelp-category.rst.j2 b/autogenerate_config_docs/templates/autohelp-category.rst.j2 index d9ce635..ee8859c 100644 --- a/autogenerate_config_docs/templates/autohelp-category.rst.j2 +++ b/autogenerate_config_docs/templates/autohelp-category.rst.j2 @@ -22,20 +22,20 @@ - {% for item in items[loop.index0] %} -{% if item[2] is equalto '' %} - * - ``{{ item[0] }}`` = +{% if item['default'] is equalto '' %} + * - ``{{ item['name'] }}`` = {% else %} - * - ``{{ item[0] }}`` = ``{{ item[2] }}`` + * - ``{{ item['name'] }}`` = ``{{ item['default'] }}`` {% endif %} -{% for paragraph in item[3] %} +{% for paragraph in item['help'] %} {% if loop.first %} - - ({{ item [1] }}) {{ paragraph }} + - ({{ item['type'] }}) {{ paragraph }} {% else %} {{ paragraph }} {% endif %} {% endfor %} -{% for flagname, flagdesc in item[4] %} +{% for flagname, flagdesc in item['flags'] %} - **{{ flagname }}** diff --git a/autogenerate_config_docs/templates/autohelp-group.rst.j2 b/autogenerate_config_docs/templates/autohelp-group.rst.j2 index 9ce0f3a..ea1504b 100644 --- a/autogenerate_config_docs/templates/autohelp-group.rst.j2 +++ b/autogenerate_config_docs/templates/autohelp-group.rst.j2 @@ -18,20 +18,20 @@ - Description {% for item in items %} -{% if item[2] is equalto '' %} - * - ``{{ item[0] }}`` = +{% if item['default'] is equalto '' %} + * - ``{{ item['name'] }}`` = {% else %} - * - ``{{ item[0] }}`` = ``{{ item[2] }}`` + * - ``{{ item['name'] }}`` = ``{{ item['default'] }}`` {% endif %} -{% for paragraph in item[3] %} +{% for paragraph in item['help'] %} {% if loop.first %} - - ({{ item [1] }}) {{ paragraph }} + - ({{ item['type'] }}) {{ paragraph }} {% else %} {{ paragraph }} {% endif %} {% endfor %} -{% for flagname, flagdesc in item[4] %} +{% for flagname, flagdesc in item['flags'] %} - **{{ flagname }}**