ajalt / clikt

Multiplatform command line interface parsing for Kotlin
https://ajalt.github.io/clikt/
Apache License 2.0
2.51k stars 121 forks source link

Consider specifying limits on `counted` #483

Closed JakeWharton closed 7 months ago

JakeWharton commented 7 months ago

Sometimes I check that a counted flag isn't too high and I either clamp it or I produce an error. It's not too hard to do myself, of course, but I figured I'd propose it for inclusion in counted directly.

Maybe

counted(limit: Int = Int.MAX_VALUE, error: Boolean = false)

This would allow

val verbosity by option("-v").counted(limit = 3)

or

val rotations by options("-r").counted(limit = 2, error = true)

but also allows this somewhat useless form

val inputCount by options("-i").counted(error = true) // never errors

Like I said, I don't need this, but I've written counted validation at least three times now so I figured it was worth proposing for inclusion.