django-elm
django-elm copied to clipboard
Create Literal flag
StringFlag has a literal option but it only validates that the string is literal and will error if that's not the case.
For example in the following CustomTypeFlag:
CustomTypeFlag(variants=[("One", StringFlag(literal="one"), ("Two", StringFlag(literal="two"))])
One might expect that a value of "one" or "two" would produce the variant that matches.
However StringFlag simply matches the first thing it sees, and then fails immediately if it's not correct.
A more correct type for this would be LiteralFlag in which case it would try all options until it found one.
CustomTypeFlag(variants=[("One", LiteralFlag("one"), ("Two", LiteralFlag("two"))])