Skip to content

Cannot properly override boolean variable from command line #1973

@wenjuno

Description

@wenjuno
  • Cookiecutter version: 2.4.0
  • Template project url: N/A
  • Python version: 3.10
  • Operating System: Linux

Description:

I tried to use the boolean variable. It works great when generating from interactive prompt. But when I try to use --no-input with command line context it doesn't propagate words like "no" or "false" as false value, but rather it seems to take it as string value, so if I pass an empty string it will be evaluated to false.

Here is my cookiecutter.json:

{
  "project_name": "test_boolean",
  "generate_text": true
}

I have a file with template:

{% if cookiecutter.generate_text %}
Hello, world!
{% endif %}

If I run cookiecutter --no-input -f . generate_text=false, the generated file still has the "Hello, world!". But if i use generate_text="" the generated file will be empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions