~ better main
authorAlexandre Bertails <bertails@w3.org>
Thu, 28 Jul 2011 11:50:41 -0400
changeset 10 9c673e76aaf8
parent 9 0ee027a61ab9
child 11 fc0a0e9197a1
~ better main
src/main/scala/FragmentDependencies.scala
--- a/src/main/scala/FragmentDependencies.scala	Thu Jul 28 11:22:58 2011 -0400
+++ b/src/main/scala/FragmentDependencies.scala	Thu Jul 28 11:50:41 2011 -0400
@@ -273,23 +273,51 @@
 
 import java.net.ResponseCache
 
+sealed trait Action
+case object Forward extends Action
+case object Backward extends Action
+case object Help extends Action
+
 object Main extends App {
 
   override def main(args: Array[String]):Unit = {
 
-    ResponseCache.setDefault(URLResolver("/home/betehess/W3C"))
+    // by default, we compute backward dependencies
+    var action:Action = Backward
 
-    args.toList match {
-      case "info" :: _ => println("blah")
-      case "dependencies" :: pages => {
+    def readArgs(args:List[String]):List[String] =
+      args match {
+        case "-dependencies" :: remainingArgs => {
+          action = Backward
+          readArgs(remainingArgs)
+        }
+        case "-impact" :: remainingArgs => {
+          action = Forward
+          readArgs(remainingArgs)
+        }
+        case "-help" :: remainingArgs => {
+          action = Help
+          readArgs(remainingArgs)
+        }
+        case "-local" :: base :: remainingArgs => {
+          ResponseCache.setDefault(URLResolver(base))
+          readArgs(remainingArgs)
+        }
+        case _ => args
+      }
+
+    val pages = readArgs(args.toList)
+
+    action match {
+      case Help => println("blah")
+      case Backward => {
         val dependencies = W3C.recipes.dependencies(pages map ( Page(_) ))
         println(dependencies.mkString(" "))
       }
-      case "impact" :: pages => {
+      case Forward => {
         val impactedPages = W3C.recipes.impactedPages(pages map ( Page(_) ))
         println(impactedPages.mkString(" "))
       }
-      case _ => println("boom")
     }
 
   }