Skip to content

Consider specifying limits on counted #483

@JakeWharton

Description

@JakeWharton

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions