kingpin icon indicating copy to clipboard operation
kingpin copied to clipboard

Basic value validation methods

Open willfaught opened this issue 8 years ago • 4 comments

It'd be useful to have basic validation methods like:

Flag(...).Positive().Int()
Flag(...).Range(1, 10).Int()
Flag(...).MatchRegexp(`\w\d\w`).String()

willfaught avatar Oct 09 '16 07:10 willfaught

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.

alecthomas avatar Oct 16 '16 11:10 alecthomas

Another thing to consider is whether they should be reflected in the help, and if so, how.

willfaught avatar Oct 16 '16 16:10 willfaught

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.

benjaminch avatar Aug 19 '17 15:08 benjaminch

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 .

alecthomas avatar Aug 19 '17 21:08 alecthomas

Closing due to no activity.

willfaught avatar Nov 19 '22 02:11 willfaught