Skip to content

Instantly share code, notes, and snippets.

@hochgi
Created December 26, 2012 05:40
Show Gist options
  • Save hochgi/4378205 to your computer and use it in GitHub Desktop.
Save hochgi/4378205 to your computer and use it in GitHub Desktop.
object Conf extends ScallopConf(args){
class BadArgsException(msg: String) extends Exception(msg) {}
val properties = props[String]('D') andThen
(_.map(_.toLowerCase)) andThen
(s => s.map { case s if(List("true","t","y","yes").contains(s)) => true
case s if(List("false","f","n","no").contains(s)) => false
case s => throw new BadArgsException(s + " is not a boolean value")
}
)
}
@Rogach
Copy link

Rogach commented Dec 26, 2012

One suggestion - if your BadArgsException would extend ScallopException instead of simple Exception, you would get a bit better error output - at least, the user wouldn't see the unneeded stack trace.

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