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