feat: use cli parsing library and return randomly 0, 100 or 200
This commit is contained in:
parent
160e8bcc1a
commit
1a7aebb5cf
@ -4,6 +4,7 @@
|
||||
// dependencies
|
||||
//> using dep com.github.j-mie6::parsley::5.0.0-M10
|
||||
//> using dep com.lihaoyi::os-lib::0.11.3
|
||||
//> using dep com.github.scopt::scopt::4.1.0
|
||||
//> using test.dep org.scalatest::scalatest::3.2.19
|
||||
|
||||
// these are all sensible defaults to catch annoying issues
|
||||
|
@ -1,16 +1,36 @@
|
||||
package wacc
|
||||
|
||||
import parsley.{Success, Failure}
|
||||
import scopt.OParser
|
||||
import java.io.File
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
println("hello WACC!")
|
||||
case class CliConfig(
|
||||
file: File = new File(".")
|
||||
)
|
||||
|
||||
args.headOption match {
|
||||
case Some(expr) =>
|
||||
parser.parse(expr) match {
|
||||
case Success(x) => println(s"$expr = $x")
|
||||
case Failure(msg) => println(msg)
|
||||
}
|
||||
case None => println("please enter an expression")
|
||||
}
|
||||
val cliBuilder = OParser.builder[CliConfig]
|
||||
val cliParser = {
|
||||
import cliBuilder._
|
||||
OParser.sequence(
|
||||
programName("wacc-compiler"),
|
||||
help('h', "help")
|
||||
.text("Prints this help message"),
|
||||
arg[File]("<file>")
|
||||
.text("Input WACC source file")
|
||||
.required()
|
||||
.action((f, c) => c.copy(file = f))
|
||||
.validate(f =>
|
||||
if (!f.exists) failure("File does not exist")
|
||||
else if (!f.isFile) failure("File must be a regular file")
|
||||
else if (!f.getName.endsWith(".wacc"))
|
||||
failure("File must have .wacc extension")
|
||||
else success
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit =
|
||||
OParser.parse(cliParser, args, CliConfig()) match {
|
||||
case Some(config) =>
|
||||
System.exit(scala.util.Random.between(0, 3) * 100)
|
||||
case None =>
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user