2
我試圖在Scala scopt 2.0.1庫中使用新的不可變的OptionParser
。由於OptionParser
需要一個泛型類型和幫助方法已經定義了返回Unit
一個動作,我得到一個編譯時錯誤:在不可變的SCOPT(Scala)OptionParser(2.0.1)中使用「help」方法
case class Config(directory: String = null)
val parser = new OptionParser[Config]() {
def options = Seq(
opt("d", "directory", "directory containing the files to be processed") {
(value: String, config: Config) => config.copy(directory = value)
},
help("?", "help", "Show a usage message and exit"))
}
error: type mismatch;
[INFO] found : scopt.generic.FlagOptionDefinition[Nothing]
[INFO] required: scopt.generic.OptionDefinition[Config]
[INFO] Note: Nothing <: Config, but class OptionDefinition is invariant in type C.
我怎麼能包括「幫助」選項?