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
|
// dependencies
|
||||||
//> using dep com.github.j-mie6::parsley::5.0.0-M10
|
//> using dep com.github.j-mie6::parsley::5.0.0-M10
|
||||||
//> using dep com.lihaoyi::os-lib::0.11.3
|
//> 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
|
//> using test.dep org.scalatest::scalatest::3.2.19
|
||||||
|
|
||||||
// these are all sensible defaults to catch annoying issues
|
// these are all sensible defaults to catch annoying issues
|
||||||
|
@ -1,16 +1,36 @@
|
|||||||
package wacc
|
package wacc
|
||||||
|
|
||||||
import parsley.{Success, Failure}
|
import scopt.OParser
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
def main(args: Array[String]): Unit = {
|
case class CliConfig(
|
||||||
println("hello WACC!")
|
file: File = new File(".")
|
||||||
|
)
|
||||||
|
|
||||||
args.headOption match {
|
val cliBuilder = OParser.builder[CliConfig]
|
||||||
case Some(expr) =>
|
val cliParser = {
|
||||||
parser.parse(expr) match {
|
import cliBuilder._
|
||||||
case Success(x) => println(s"$expr = $x")
|
OParser.sequence(
|
||||||
case Failure(msg) => println(msg)
|
programName("wacc-compiler"),
|
||||||
}
|
help('h', "help")
|
||||||
case None => println("please enter an expression")
|
.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