我正在尝试OptionParser
在 Scala scopt 2.0.1 库中使用新的不可变对象。由于OptionParser
采用泛型类型并且 help 方法已经定义了一个返回的操作 Unit
,我得到一个编译时错误:
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.
如何包含“帮助”选项?