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

Allow specifying allowed options? #193

Open
richtier opened this issue Jul 20, 2018 · 4 comments
Open

Allow specifying allowed options? #193

richtier opened this issue Jul 20, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@richtier
Copy link

It would be great to detect an env var has been misconfigured by optionally providing a list of valid choices for the value.

It seems this is not currently supported.

Is this on the roadmap? I'm happy to contribute this feature.

@Jafnee
Copy link

Jafnee commented May 19, 2019

@richtier @joke2k What do you think of having like this:

# (env variable, list of choices, optional default value)
MY_SETTING = env.choices('MY_ENV', ['choice_1', 'choice_2', 'choice_3'], 'choice_3')

Or maybe as a new kwarg instead:

MY_SETTING = env.str('MY_ENV', choices=['choice_1', 'choice_2', 'choice_3'], 'choices_3')
MY_SETTING = env.int('MY_ENV', choices=[123, 456, 789, 0], 0)

@sergeyklay sergeyklay added the enhancement New feature or request label Sep 7, 2021
@QuentinAndre11
Copy link

@richtier @joke2k I subclassed my Enum classes with a "cast" function which did the trick for string based enums, are you interested in a PR based on the idea of adding the Enum type ?

@pataquets
Copy link

Just adding an use case which clearly would benefit from this (and would also make for a good example code snippet): the LOGLEVEL variable, which could only be DEBUG, INFO, etc.

@pataquets
Copy link

@sergeyklay @joke2k In case anyone wants to pick it up, would such a PR be acceptable? Seems quite a low-risk, self-contained feature with no apparent side-effects. Wdyt?

@QuentinAndre11: is your code posted publicly somewhere to check?
Also, calling to those still interested in contributing to kindly chime in/thumbs up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants