Variable types
Boolean
Boolean variables are used for answering True/False questions.
Basic Usage
Boolean variables are regular key / value pairs, but with the value being
True
/False
.
For example, if you provide the following boolean variable in your questions file:
questions:
- name: "run_as_docker"
schema:
type: boolean
default: true
you will get the following user input when running mk-scaffold:
run_as_docker [True]:
The following values are considered as valid user input:
True
values: “1”, “true”, “t”, “yes”, “y”
False
values: “0”, “false”, “f”, “no”, “n”
The above run_as_docker
boolean variable creates scaffold.run_as_docker
,
which can be used like this:
{%- if scaffold.run_as_docker -%}
# In case of True add your content here
{%- else -%}
# In case of False add your content here
{% endif %}
scaffold is using Jinja2’s if conditional expression to determine the correct run_as_docker
.
Allowed Variables
Allowed variables provide different choices when creating a project. Depending on a user’s choice the template renders things differently.
Basic Usage
Allowed variables are regular key / value pairs, but with the allowed value being from a list of strings.
For example, if you provide the following allowed variable in your questions file:
- name: "python_min_version"
if: "{{ scaffold.use_python }}"
schema:
default: "3.7"
allowed: [
"3.6",
"3.7",
"3.8",
"3.9",
]
you’d get a simple prompt when running mk-scaffold that only accepts a value from [ “3.6”, “3.7”, “3.8”, “3.9” ].
The above python_min_version
allowed variable creates scaffold.python_min_version
, which can be used like this:
{%- if scaffold.python_min_version == "3.6" -%}
# Possible 3.6 content here
{%- elif scaffold.python_min_version == "3.7" -%}
# More possible 3.7 content here
{% endif %}
mk-Scaffold is using Jinja2’s if conditional expression to determine the correct Python minimal version.
The created allowed variable is still a regular Cookiecutter variable and can be used like this:
Requirements
------------
Minimal required Python version is `{{scaffold.python_min_version}}`.