scala_cli_parser
-
dev
: -
Available for Scala
2.11
(both JVM and Scala Native),2.12
and2.13
.
A library for parsing command line arguments.
It’s main feature is that CLI parsing is defined on a config file. For example consider a very simple sum program:
import fmv1992.fmv1992_scala_utilities.util.S
object TestSum extends CLIConfigTestableMain {
val version = "0.0.0"
val programName = "TestSum"
val CLIConfigContents =
S.putfile("./src/test/resources/test_cli_example_02_gnu.txt")
def testableMain(args: Seq[Argument]): List[String] = {
val res = args.foldLeft(0)((l, x) => {
x match {
case y: Argument if y.longName == "sum" => x.value.map(_.toInt).sum + l
case _ => println(x); throw new Exception()
}
})
List(res.toString)
}
}
It can be configured with the following config file:
name: version
n: 0
type: int
help: Help text.
name: help
n: 0
type: int
help: Help text.
name: sum
n: 2
type: int
help: Sum arguments.
# vim: set filetype=config fileformat=unix wrap:
And its usages are as follows:
-
TestSum --version
TestSum 0.0.0
-
TestSum --help
TestSum --debug --help --sum --version --debug: Turn on debugging. --help: Help text. --sum: Sum arguments. --version: Show the program version.
-
TestSum --sum 1992 1
1993