Skip to content

Instantly share code, notes, and snippets.

@aishfenton
Created February 18, 2017 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aishfenton/9ea79b24d51678046afedbef3fe66a39 to your computer and use it in GitHub Desktop.
Save aishfenton/9ea79b24d51678046afedbef3fe66a39 to your computer and use it in GitHub Desktop.
Scopt range parser
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
}
}
@aishfenton
Copy link
Author

For dealing with params such as --cols 1-5,7,9-10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment