Improved check for choices and default value#57
Open
phospi wants to merge 5 commits intoansible-network:masterfrom
Open
Improved check for choices and default value#57phospi wants to merge 5 commits intoansible-network:masterfrom
phospi wants to merge 5 commits intoansible-network:masterfrom
Conversation
|
The problem you are seeing here is because of a breaking change in Jinja2 3.0.0. I would suggest instead of your current solution the following: diff --git a/collection_prep/cmd/plugin.rst.j2 b/collection_prep/cmd/plugin.rst.j2
index 5cf357a..d2271ad 100644
--- a/collection_prep/cmd/plugin.rst.j2
+++ b/collection_prep/cmd/plugin.rst.j2
@@ -153,7 +153,7 @@ Parameters
</ul>
{% endif %}
{# Show default value, when multiple choice or no choices #}
- {% if value.default is defined and value.default not in value.choices %}
+ {% if value.default is defined and (not value.choices or (value.default not in value.choices)) %}
<b>Default:</b><br/><div style="color: blue">@{ value.default | tojson | escape }@</div>
{% endif %}
</td>With your change the default value won't be printed unless there are choices. |
Author
|
Ahh... good to know. You are right. Your suggestion fixes the issue. |
Author
|
Solved merge conflict. This PR is ready for merge. |
Author
|
Can someone please review this PR? |
goneri
approved these changes
Dec 2, 2021
Author
|
Can someone please review this PR this year? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I created this PR because I am observing that the following
options-documenation is parsed with an error:The error message looks like this:
Solution Discussion
Now I see a lot of room for discussion about different approaches to the issue:
1. Is the above documentation example a correct documentation?
I don't know for sure. I read the Guide here and there is no imperative to leave
defaultout, if there are no choices. However, between the lines you get the idea that if values are empty, you should leave out the keys as well. However, the jinja template fails as well for me if a default value is given, e.g.default: Test. Because there is still nochoiceskey.2. Change the documentation
Obviously we can remove
default:but we have no obligation to do so. If that should be the solution then we should catch the error and inform the user.3. Add choices to documentation
The below documentation example works without error.