From d5673117d735352ca8f93a214174b5e0c1598d6f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 15 Aug 2022 13:46:33 +0200 Subject: [PATCH] Convert 'default', 'choices', 'sample' to type; change booleans to 'true' and 'false' (#19) * Normalize booleans to 'true' and 'false' instead of 'yes' and 'no'. * Began with default / sample / choices format adjustment. * Vendor code from ansible/ansible. * Add changelog fragment. * Fix tests. --- LICENSES/BSD-2-Clause.txt | 8 + .../fragments/19-type-conversion-booleans.yml | 3 + .../data/docsite/macros/parameters.rst.j2 | 28 +- .../data/docsite/macros/returnvalues.rst.j2 | 12 +- src/antsibull_docs/schemas/docs/base.py | 87 ++- src/antsibull_docs/schemas/docs/plugin.py | 12 +- src/antsibull_docs/vendored/ansible.py | 503 ++++++++++++++++++ .../schema/good_data/ssh_connection.json | 2 +- .../good_data/ssh_connection_results.json | 6 +- 9 files changed, 631 insertions(+), 30 deletions(-) create mode 100644 LICENSES/BSD-2-Clause.txt create mode 100644 changelogs/fragments/19-type-conversion-booleans.yml create mode 100644 src/antsibull_docs/vendored/ansible.py diff --git a/LICENSES/BSD-2-Clause.txt b/LICENSES/BSD-2-Clause.txt new file mode 100644 index 00000000..6810e04e --- /dev/null +++ b/LICENSES/BSD-2-Clause.txt @@ -0,0 +1,8 @@ +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/changelogs/fragments/19-type-conversion-booleans.yml b/changelogs/fragments/19-type-conversion-booleans.yml new file mode 100644 index 00000000..c4f85b97 --- /dev/null +++ b/changelogs/fragments/19-type-conversion-booleans.yml @@ -0,0 +1,3 @@ +minor_changes: + - "Ensure that values for ``default``, ``choices``, and ``sample`` use the types specified for the option / return value (https://github.com/ansible-community/antsibull-docs/pull/19)." + - "Use ``true`` and ``false`` for booleans instead of ``yes`` and ``no`` (https://github.com/ansible-community/community-topics/issues/116, https://github.com/ansible-community/antsibull-docs/pull/19)." diff --git a/src/antsibull_docs/data/docsite/macros/parameters.rst.j2 b/src/antsibull_docs/data/docsite/macros/parameters.rst.j2 index 7b286d9b..c25dfe56 100644 --- a/src/antsibull_docs/data/docsite/macros/parameters.rst.j2 +++ b/src/antsibull_docs/data/docsite/macros/parameters.rst.j2 @@ -76,14 +76,14 @@ {% endfor %} {# default / choices #} -{# Turn boolean values in 'yes' and 'no' values #} +{# Turn boolean values in 'true' and 'false' values #} {% if value['default'] is sameas true %} -{% set _x = value.update({'default': 'yes'}) %} +{% set _x = value.update({'default': 'true'}) %} {% elif value['default'] is not none and value['default'] is sameas false %} -{% set _x = value.update({'default': 'no'}) %} +{% set _x = value.update({'default': 'false'}) %} {% endif %} {% if value['type'] == 'bool' %} -{% set _x = value.update({'choices': ['no', 'yes']}) %} +{% set _x = value.update({'choices': ['false', 'true']}) %} {% endif %} {# Show possible choices and highlight details #} {% if value['choices'] %} @@ -93,11 +93,11 @@ :ansible-option-choices:`Choices:` {% for choice in value['choices'] %} -{# Turn boolean values in 'yes' and 'no' values #} +{# Turn boolean values in 'true' and 'false' values #} {% if choice is sameas true %} -{% set choice = 'yes' %} +{% set choice = 'true' %} {% elif choice is sameas false %} -{% set choice = 'no' %} +{% set choice = 'false' %} {% endif %} {% if (value['default'] is not list and value['default'] == choice) or (value['default'] is list and choice in value['default']) %} - :ansible-option-default-bold:`@{ choice | rst_escape(escape_ending_whitespace=true) }@` :ansible-option-default:`← (default)` @@ -226,25 +226,25 @@

@{ desc | html_ify | indent(6, blank=true) }@

{% endfor %} {# default / choices #} -{# Turn boolean values in 'yes' and 'no' values #} +{# Turn boolean values in 'true' and 'false' values #} {% if value['default'] is sameas true %} -{% set _x = value.update({'default': 'yes'}) %} +{% set _x = value.update({'default': 'true'}) %} {% elif value['default'] is not none and value['default'] is sameas false %} -{% set _x = value.update({'default': 'no'}) %} +{% set _x = value.update({'default': 'false'}) %} {% endif %} {% if value['type'] == 'bool' %} -{% set _x = value.update({'choices': ['no', 'yes']}) %} +{% set _x = value.update({'choices': ['false', 'true']}) %} {% endif %} {# Show possible choices and highlight details #} {% if value['choices'] %}

Choices: