scala libraryDependencies += "com.lihaoyi" %% "mainargs" % "0.2.12" scala import org.mainargs._ @maincase class HelloWorldParams( @arg(default = "World") name: String, @arg(doc = "The number of times to repeat the message") count: Int ) object HelloWorld extends App { @doc("Print a hello message to the specified name") def main(@arg(name = "name", doc = "The name to greet") name: String): Unit = { println(s"Hello, $name!") } @doc("Print a hello message to the specified name multiple times") def repeat(params: HelloWorldParams): Unit = { for (_ <- 1 to params.count) { println(s"Hello, ${params.name}!") } } CommandLineParser.execute(args) } shell scala HelloWorld.scala main Bob shell scala HelloWorld.scala repeat --name Bob --count 3


上一篇:
下一篇:
切换中文