Main.scala 1.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* 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



}