Skip to content

Instantly share code, notes, and snippets.

@Pablo-Leon
Created May 28, 2016 20:02
Show Gist options
  • Save Pablo-Leon/1dc2fa6afd24bd756bbc5fb7e11bb614 to your computer and use it in GitHub Desktop.
Save Pablo-Leon/1dc2fa6afd24bd756bbc5fb7e11bb614 to your computer and use it in GitHub Desktop.
#!/bin/sh
exec scalas $0 $@
!#
/***
// scalaVersion := "2.11.8"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.2"
libraryDependencies += "com.github.scopt" %% "scopt" % "3.4.0"
*/
import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._
// import com.typesafe.scalalogging._
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scopt._
import java.io.File
case class Config(
foo: Int = -1
,flag: Boolean = false
)
// object HelloSbt extends App {
println("Sbt says Hello!!")
val now = new Date
val df = getDateInstance(LONG, Locale.FRANCE)
println(df format now)
val logger = LoggerFactory.getLogger("main")
logger.info("info ...")
logger.debug("debug ...")
// }
val parser = new scopt.OptionParser[Config]("scopt") {
head("scopt", "3.x")
opt[Int]('f', "foo") action { (x, c) =>
c.copy(foo = x) } text("foo is an integer property")
note("some notes.\n")
help("help") text("prints this usage text")
opt[Unit]("flag") action { (_, c) =>
c.copy(flag = true) } text("this option is not hidden in the usage text")
}
// parser.parse returns Option[C]
val result = parser.parse(args, Config()) map { config =>
// do stuff
println("do stuff ..." + config.foo)
} getOrElse {
// arguments are bad, usage message will have been displayed
println("arguments are bad ...")
}
@Pablo-Leon
Copy link
Author

Pablo-Leon commented May 28, 2016

Incomplete, but the autodep resolution works

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