我想使用(或类似但基于 Scala)声明所需的子命令。scopt
例如,我想有以下概要(类似于man git
,例如):
mycli [--version] [--help] <command> [<args>]
而需要<command>
是子命令之一,例如,和。类似于以下内容:subA
subB
private val parser = new OptionParser[Config]("mycli") {
head(s"${BuildInfo.name} v${BuildInfo.version} is © 2014 by ${BuildInfo.organization}")
help("help") text("prints this usage text")
version("version") text("FIXME”)
cmd("command") required() action {(c, config) => c match {
case "subA" => config.copy(mode = "subA") children(
arg[String]("<files>...") unbounded() optional() action {(rs, config) => config.copy(files = config.files :+ rs) },
opt[Unit] ("with-optA") action {(_ , config) => config.copy(optA = true)},
opt[Unit] ("with-optB") action {(_ , config) => config.copy(optB = true)})
case "subB" => //...
case _ => // ERROR!
} }
}
有什么提示吗?
在此先感谢您的帮助!