Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please, inform which are the valid values in docs advanced/boolean_variables.html #1695

Closed
italomaia opened this issue Jun 6, 2022 · 8 comments
Labels
documentation This issue/PR relates to or includes documentation. question User questions

Comments

@italomaia
Copy link
Contributor

Description:

Could you please inform which are the valid values for a boolean configuration variable? Will "y" coerce to True? What about "yes"? What about "n" and "no"? What about "true"?

@insspb
Copy link
Member

insspb commented Jun 6, 2022

Hi @italomaia, are you asking about this feature?
https://cookiecutter.readthedocs.io/en/latest/advanced/boolean_variables.html

In json specification it is only true or false. this feature is not released to pip (2.2+)

@insspb insspb added the question User questions label Jun 6, 2022
@alkatar21
Copy link
Contributor

I think the question is not what you can specify in json, but what users can specify on the command line for true/false during generation. The question I have also asked myself, what all works there?

@italomaia
Copy link
Contributor Author

@insspb I refer to the user input. Documentation informs how to create an boolean configuration but not what counts as a true or false user input. Is there any pre-procession? Does the user have to write specifically True or False when prompted?

@luzfcb
Copy link
Contributor

luzfcb commented Jun 6, 2022

Good question. For Python projects in general (not specifically about cookiecutter) I use this implementation to deal with boolean values when having user input:

TRUE_VALUES = {'y', 'yes', 't', 'true', 'on', '1'}
FALSE_VALUES = {'n', 'no', 'f', 'false', 'off', '0'}


def strtobool(value):
    if isinstance(value, bool):
        return value
    value = value.lower()

    if value in TRUE_VALUES:
        return True
    elif value in FALSE_VALUES:
        return False

    raise ValueError(f'Invalid truth value: {value}')

That said, I don't know whether or not it would be nice to support such a "wide" set of options.

@italomaia
Copy link
Contributor Author

@luzfcb which is reasonable. We need clarity regarding how cookiecutter does it. Can the ticket be rebranded, as it is not a question?

@luzfcb
Copy link
Contributor

luzfcb commented Jun 6, 2022

@italomaia I guess it is only necessary to update the documentation.
In theory, these are the supported values:

def read_user_yes_no(question, default_value):
"""Prompt the user to reply with 'yes' or 'no' (or equivalent values).
Note:
Possible choices are 'true', '1', 'yes', 'y' or 'false', '0', 'no', 'n'
:param str question: Question to the user
:param default_value: Value that will be returned if no input happens
"""
# Please see https://click.palletsprojects.com/en/7.x/api/#click.prompt
return click.prompt(question, default=default_value, type=click.BOOL)

@italomaia
Copy link
Contributor Author

Indeed. MR available: #1705

@insspb insspb added the documentation This issue/PR relates to or includes documentation. label Jun 7, 2022
@insspb
Copy link
Member

insspb commented Jun 7, 2022

@italomaia @luzfcb Thank you for contribution and asking this question. Updated docstrings and documentation. Check as 'latest' hope now everything clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This issue/PR relates to or includes documentation. question User questions
Projects
None yet
Development

No branches or pull requests

4 participants