django-elm icon indicating copy to clipboard operation
django-elm copied to clipboard

Create Literal flag

Open Confidenceman02 opened this issue 9 months ago • 0 comments

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"))])

Confidenceman02 avatar Mar 20 '25 13:03 Confidenceman02