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

Already on GitHub? Sign in to your account

Added support of choices to options. #970

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants

With this feature, it's possible to check an option from a restricted set of values. This feature is quite similar to the Python's argparse module.

puentesarrin added some commits Jan 3, 2014

Added support of choices to options.
With this feature, it's possible to check an option from a restricted
set of values. This feature is quite similar to the Python's argparse
module.
Owner

bdarnell commented Jan 4, 2014

Should choices be another parameter to the option definition, or is it a kind of type? In python 3.4 setting type to an enum class would be a natural way to express an option that can only take on certain values. (this almost works today - you can set type=MyEnum.__getitem__. A parse hook like the one we use for datetimes and bools would fix this). The Enum class is backported for older pythons (pip install enum34), or it would be easy to define our own type so you could say "define('foo', type=Choices('a', 'b', 'c'))". I think I prefer this approach to adding a top-level "choices" parameter that must be considered in combination with all the other flags.

I had not thought on this approach and I think you're absolutely right, I will work on it now. Do you prefer to close the pull request and start another one, or keep it and revert the commits?

@bdarnell bdarnell added the options label Jul 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment