forked from scallop/scallop
-
Notifications
You must be signed in to change notification settings - Fork 0
Subcommands
Rogach edited this page Jun 2, 2012
·
2 revisions
Scallop supports parsing of subcommands - like git push
and git pull
, for example .
For example:
object Conf extends ScallopConf(Seq("-a", "tree", "-b")) {
val apples = opt[Boolean]("apples")
val tree = new Subcommand("tree") {
val bananas = opt[Boolean]("bananas")
}
}
Conf.apples() should equal (true)
Conf.subcommand should equal (Some(Conf.tree))
Conf.subcommands should equal (List(Conf.tree))
Conf.tree.bananas() should equal (true)
All the usual operations with options - relationships, .isSupplied
, etc. - also work transparently.
Note that you can nest subcommands to infinite depth:
object Conf extends ScallopConf(Seq("sub1", "sub2", "sub3", "sub4", "win!")) {
val sub1 = new Subcommand("sub1") {
val sub2 = new Subcommand("sub2") {
val sub3 = new Subcommand("sub3") {
val sub4 = new Subcommand("sub4") {
val opts = trailArg[List[String]]()
}
}
}
}
}
Conf.subcommands should equal (List(Conf.sub1, Conf.sub1.sub2, Conf.sub1.sub2.sub3, Conf.sub1.sub2.sub3.sub4))
Conf.sub1.sub2.sub3.sub4.opts() should equal (List("win!"))