Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import com.twitter.app.App
object MyApp extends App {
// parses an integer from the "-port" flag.
// Finagle already provides an implicit Flaggable typeclass for Int
// usage: -port 9000
val port = flag[Int]("port", 8080, "port this server should use")
// parses an Env trait. See typeclass below
val env = flag[Env]("env", Env.Dev, "environment this server runs")
sealed trait Env
case object Prod extends Env
case object Dev extends Env
implicit val flaggableEnv = new Flaggable[Env] {
override def parse(env: String): Env = env match {
case "prod" => Prod
case "dev" => Dev
}
}
// best practice to turn this on.
// The app won't start if parameters are wrong or missing
override def failfastOnFlagsNotParsed: Boolean = true
def main() {
// access the port simply with the apply method.
// There are also other ways (get, getWithDefault)
println(s"Hello, World ${port()}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment