Skip to content

Instantly share code, notes, and snippets.

@natechols
Created May 27, 2016 01:49
Show Gist options
  • Save natechols/58dab6ba62b04b778d4cbed4c9276e70 to your computer and use it in GitHub Desktop.
Save natechols/58dab6ba62b04b778d4cbed4c9276e70 to your computer and use it in GitHub Desktop.
import scopt.OptionParser
case class BaseConfig(host: String, port: Int)
trait BaseParser { self: OptionParser[BaseConfig] =>
opt[String]("host") action { (x, c) =>
c.copy(host = x)
} text "Hostname of smrt server"
opt[Int]("port") action { (x, c) =>
c.copy(port = x)
} text "Services port on smrt server"
}
object BaseProgram {
lazy val parser = new OptionParser[BaseConfig]("basic-config") with BaseParser {
head("This is the basic program", "0.0.1")
}
}
case class ExtendedConfig(host: String, port: Int, uiPort: Int)
trait ExtendedParser { self: OptionParser[ExtendedConfig] =>
opt[Int]("ui-port") action { (x, c) =>
c.copy(uiPort = x)
} text "GUI port on smrt server"
}
object ExtendedProgram {
lazy val parser = new OptionParser[ExtendedConfig]("extended-config") with BaseParser with ExtendedParser {
head("This is the more fully-featured program")
}
}
@natechols
Copy link
Author

natechols commented May 27, 2016

This fails:

BadOptions.scala:33: illegal inheritance;
[error]  self-type scopt.OptionParser[ExtendedConfig] with BaseParser with ExtendedParser does not conform to BaseParser's selftype BaseParser with scopt.OptionParser[BaseConfig]
[error]   lazy val parser = new OptionParser[ExtendedConfig]("extended-config") with BaseParser with ExtendedParser {
[error]                                                                              ^

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