fix: Booleans don't work if a value is defined
feinstein opened this issue · comments
I have a boolean variable and if I select No
in the prompt it works fine, but if I define it as No
or false
in a json file, the variable is defined and the template behaves as if the variable was true. I think this happens because mustache only evaluates if the variable exists or not, and not it's inner value.
I can delete the property from the json configuration file, but it makes it a lot easier if I can keep all variables there and just change their values. Also, if I don't define this variable the prompt will ask me what it's value, so I need to place a manual input.
Hi @feinstein 👋
Can you please provide a minimal reproduction sample? Thanks!
Sure :)
Add this variable to your brick.yaml
:
shouldGenerateExample:
type: boolean
description: If an example feature should be generated
default: false
prompt: Generate example code?
And create a json file with contents like:
{
...
"shouldGenerateExample": "false"
}
Create a folder named {{#shouldGenerateExample}}example_feature{{
and inside it put another named shouldGenerateExample}}
and inside this folder place some files.
Now call make my_brick_name -o ./test_app -c test_properties.json
and the example_feature
folder will be created, even though the variable was set as false
. I think this happens because mustache checks for a key's existence and not its value.
Sure :)
Add this variable to your
brick.yaml
:shouldGenerateExample: type: boolean description: If an example feature should be generated default: false prompt: Generate example code?And create a json file with contents like:
{ ... "shouldGenerateExample": "false" }Create a folder named
{{#shouldGenerateExample}}example_feature{{
and inside it put another namedshouldGenerateExample}}
and inside this folder place some files.Now call
make my_brick_name -o ./test_app -c test_properties.json
and theexample_feature
folder will be created, even though the variable was set asfalse
. I think this happens because mustache checks for a key's existence and not its value.
Are you sure this isn’t due to the fact that you’re setting the variable to the string “false”?
Have you tried changing your json to:
{
...
"shouldGenerateExample": false
}
@feinstein closing this for now since I believe there are no actionable steps to be taken. Let me know if my suggestion does not work for you and I’m happy to take a closer look.
@felangel ouch, sorry! lol this was a very stupid mistake on my part!
@felangel ouch, sorry! lol this was a very stupid mistake on my part!
No problem at all!