Commit 02a544f8 authored by Eva Darulova's avatar Eva Darulova
Browse files

setting up and some option processing

parents
Project Daisy
name := "Daisy"
version := "0.0"
organization := "ch.epfl.lara"
scalaVersion := "2.11.6"
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature"
)
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % "2.11.6",
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
"com.typesafe.akka" %% "akka-actor" % "2.3.9"
)
\ No newline at end of file
sbt.version=0.13.8
\ No newline at end of file
/* Copyright 2015 EPFL, Lausanne */
package daisy
abstract class OptionDef {
val name: String
val usage: String
val description: String
}
case class FlagOptionDef(name: String, usage: String, description: String) extends OptionDef
case class NumericOptionDef(name: String, usage: String, description: String) extends OptionDef
case class ListOptionDef(name: String, usage: String, description: String) extends OptionDef
abstract class DaisyOption {
val name: String
}
/** Boolean option, present means on. **/
case class FlagOption(name: String) extends DaisyOption
case class NumericOption(name: String, value: Int) extends DaisyOption
case class ListOption(name: String, value: List[String]) extends DaisyOption
\ No newline at end of file
/* Copyright 2015 EPFL, Lausanne */
package daisy
object Main {
val globalOptions: Set[OptionDef] = Set(
FlagOptionDef("help", "--help", "Show this message"),
NumericOptionDef("timeout", "--timeout=1000", "Timeout in ms"),
ListOptionDef("opts", "--opts=o1:o2", "Random options")
)
def main(args: Array[String]) {
println("Hej, this is Daisy.")
println("arguments: " + args.mkString(" / "))
val options = processOptions(args.toList)
println(options)
// TODO: set up reporter
// TODO: set up pipeline
}
private def processOptions(args: List[String]): List[DaisyOption] = {
// all available options from all phases
val allOptions = globalOptions.map(o => o.name -> o).toMap
val options = args.filter(_.startsWith("--"))
val files = args.filterNot(_.startsWith("-")).map(new java.io.File(_))
println("files: " + files)
var validOptions: List[DaisyOption] = List()
for (opt <- options) {
opt.drop(2).split("=", 2).toList match {
case List(name, value) =>
allOptions.get(name) match {
case Some(ints: NumericOptionDef) if (value.forall(_.isDigit)) =>
validOptions +:= NumericOption(name, value.toInt)
case Some(lists: ListOptionDef) =>
validOptions +:= ListOption(name, value.split(":").toList)
case _ =>
println(s"Unknown option: $name, $value")
// TODO: add reporter
}
case List(name) =>
allOptions.get(name) match {
case Some(flg: FlagOptionDef) =>
validOptions +:= FlagOption(name)
case _ =>
println(s"Unknown option: $name")
// TODO: add reporter
}
}
}
validOptions
}
// TODO: process options
// TODO: help options
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment