Created
February 18, 2017 21:42
-
-
Save aishfenton/9ea79b24d51678046afedbef3fe66a39 to your computer and use it in GitHub Desktop.
Scopt range parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val listIntRead: scopt.Read[List[Int]] = | |
scopt.Read.reads { str => | |
val parts = str.split(",").map(_.trim).toList | |
parts.flatMap { p => | |
if (p.contains("-")) { | |
val (start :: end :: Nil) = p.split("-").map(_.trim.toInt).toList | |
Range(start, end + 1).toList | |
} | |
else p.toInt :: Nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For dealing with params such as
--cols 1-5,7,9-10