【发布时间】:2016-03-31 10:47:18
【问题描述】:
对于 scopt 的以下使用:
import java.io.File
object Application extends App {
case class Config(in: File = new File("."), out: File = new File("."), scripts: Seq[File] = Seq())
val parser = new scopt.OptionParser[Config]("scopt") {
head("Script Runner", "0.1")
opt[File]('i', "in") required () valueName ("<path>") action { (x, c) =>
c.copy(in = x)
} text ("required in path property")
opt[File]('o', "out") required () valueName ("<path>") action { (x, c) =>
c.copy(out = x)
} text ("required out path file property")
arg[File]("<file>...") unbounded () required() action { (x, c) =>
c.copy(scripts = c.scripts :+ x)
} text ("unbounded script paths")
}
val config = parser.parse(args, Config())
val scripts = config.map { argConfig => argConfig.scripts }
config match {
case Some(config) => println(config)
case _ => println("config undefined")
}
}
我得到编译错误:
[error] /Users/jamesclark/code/scratch/src/main/scala/Application.scala:13: not found: value x
[error] c.copy(out = x)
如果我重命名 Config 参数 scripts 或 val scripts,那么它会编译。
谁能告诉我这里发生了什么? 是编译器问题,还是我错过了一些魔法?
scala 2.11.8 / sbt 0.13.7 / scopt 3.5.0
【问题讨论】: