With --no--input, input validation is disabled and boolean unusable
- Cookiecutter version: 2.6.0
- Template project url: https://oslandia.gitlab.io/qgis/template-qgis-plugin/
- Python version: 3.12.3
- Operating System: Ubuntu 24.04
Description:
I'm trying to use boolean values in template option as documented here: https://cookiecutter.readthedocs.io/en/stable/advanced/boolean_variables.html#basic-usage.
Specifically:
- input validation: is value a valid boolean, i.e. one of
- it's possible to test value within template using jinja's syntax
I've just edited my template with the documentation option (see latest line):
{
[...]
"run_as_docker": true
}What I've run:
Input validation is not working with --no-input option
cookiecutter --no-input -f ~/Git/Oslandia/QGIS/template-qgis-plugin/ plugin_name=issue_processing_option run_as_docker=docker --verboseI can passe anything to boolean option. I guess it's not a bug and using --no-input disable validation? If so, we should update the documentation (or well pointing me on where it's stipulated, I might missed something).
Boolean test does not work
Then let's say I've something like the following in my template files:
{{ cookiecutter.run_as_docker }} {{ cookiecutter.run_as_docker is boolean }}
{% if cookiecutter.run_as_docker %}
Containers ON.
{% else %}
No container.
{% endif %}If I run:
cookiecutter -f ~/Git/Oslandia/QGIS/template-qgis-plugin/ plugin_name=issue_processing_optionAnswering y or n, I've the correct result.
But if I run with --no--input, it does not work:
cookiecutter -f ~/Git/Oslandia/QGIS/template-qgis-plugin/ plugin_name=issue_processing_option run_as_docker=true --no-input
# or
cookiecutter -f ~/Git/Oslandia/QGIS/template-qgis-plugin/ plugin_name=issue_processing_option run_as_docker=false --no-inputrun_as_docker is a string and {% if cookiecutter.run_as_docker %} always True:
false False
Containers ON.
So --no-input is not compatible with input types other than string?
Source: cookiecutter/cookiecutter