Unsuported options field prompt as string
For example this .json
raises an error:
{
"git_base_url": "https://github.com/ai4os-hub",
"open_source_license": ["MIT", "Apache 2.0", "BSD-3-Clause", "No license file"],
"__prompts__": {
"git_base_url": "Some text",
"open_source_license": "Some text"
}
}
Error:
Exception has occurred: AttributeError
'str' object has no attribute 'get'
File "/home/borja/projects/cookiecutter-web/backend/app/utils.py", line 52, in parse_field
data["prompt"] = prompt.get("__prompt__", None) if prompt else None
^^^^^^^^^^
File "/home/borja/projects/cookiecutter-web/backend/app/utils.py", line 33, in parse_fields
data[name] = parse_field(name, value, prompts.get(name, None))
File "/home/borja/projects/cookiecutter-web/backend/app/api_v1/endpoints/project.py", line 84, in fetch_fields
return utils.parse_fields(data)
File "<string>", line 1, in <module>
AttributeError: 'str' object has no attribute 'get'
Basically it means it was expecting a dict
and not a string as the prompt.
How to form it is the one at the documentation.
From https://cookiecutter.readthedocs.io/en/stable/advanced/human_readable_prompts.html
{
"package_name": "my-package",
"linting": ["ruff", "flake8", "none"],
"__prompts__": {
"package_name": "Select your package name",
"linting": {
"__prompt__": "Which linting tool do you want to use?",
"ruff": "Ruff",
"flake8": "Flake8",
"none": "No linting tool"
}
}
}
Where the "lintin" is a sub json
with "prompt" inside.
However, cookicutter seems to work without any problem when the prompt is just a string and not a json. Therefore probably the best is to also provide support for this feature or at least provide a more informative error.