Skip to content

Instantly share code, notes, and snippets.

@muuki88
Created July 23, 2016 10:45
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 muuki88/e91b6ea1dc4ef6f2a4815e5cdca041dd to your computer and use it in GitHub Desktop.
Save muuki88/e91b6ea1dc4ef6f2a4815e5cdca041dd to your computer and use it in GitHub Desktop.
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