CITGuru / PyInquirer

A Python module for common interactive command line user interfaces
MIT License
1.91k stars 235 forks source link

Default value is not added to answers if when evaluates to False #130

Open SethMMorton opened 3 years ago

SethMMorton commented 3 years ago
import PyInquirer

answers = PyInquirer.prompt(
    [
        {
            "type": "confirm",
            "message": "Do it:",
            "name": "DO_IT",
            "default: True,
            "when": lambda x: "THING" in x,
        }
    ]
)
print(answers)  # {}

I would have expected the result to be {"DO_IT": True}, because that is the default. My expectation is the default is resolved even if not asked - in fact, it is my opinion that the default is especially important if the question is not asked.

This could be solved by adding the default to the answers dictionary before the when is evaluated.