kingpin
kingpin copied to clipboard
Basic value validation methods
It'd be useful to have basic validation methods like:
Flag(...).Positive().Int()
Flag(...).Range(1, 10).Int()
Flag(...).MatchRegexp(`\w\d\w`).String()
On the one hand I feel like this is a slippery slope, given how many different data types and potential validators there are. On the other hand, it does make those use cases it covers much more convenient.
Another thing to consider is whether they should be reflected in the help, and if so, how.
Thinking about it, maybe would be good to add a case where we allow the flag to take only some values.
Flag(...).OneOf('jpg', 'png', 'gif').String()
Would be nice to add those in help as well with a default text for every validation check which should be overridable as well if needed.
Enum() does this already, but only for strings. On Sun, 20 Aug 2017 at 1:58 am, Benjamin [email protected] wrote:
Thinking about it, maybe would be good to add a case where we allow the flag to take only some values. Flag(...).OneOf('jpg', 'png', 'gif').String()
Would be nice to add those in help as well with a default text for every validation check which should be overridable as well if needed.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/alecthomas/kingpin/issues/153#issuecomment-323531483, or mute the thread https://github.com/notifications/unsubscribe-auth/AACjJ0v7eFtHcWJXMrKM98IlwV0CO-kBks5sZwYJgaJpZM4KR8Ac .
Closing due to no activity.