【发布时间】:2012-03-27 15:51:01
【问题描述】:
我正在尝试在 Scala scopt 2.0.1 库中使用新的不可变 OptionParser。由于OptionParser 采用泛型类型并且帮助方法已经定义了一个返回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.
如何添加“帮助”选项?
【问题讨论】: