~ move the command line app to Main.scala default tip
authorAlexandre Bertails <bertails@w3.org>
Fri, 29 Jul 2011 15:22:24 -0400
changeset 14 c95e62f4f343
parent 13 2ef59024b47f
~ move the command line app to Main.scala
src/main/scala/FragmentDependencies.scala
src/main/scala/Main.scala
--- a/src/main/scala/FragmentDependencies.scala	Fri Jul 29 15:20:35 2011 -0400
+++ b/src/main/scala/FragmentDependencies.scala	Fri Jul 29 15:22:24 2011 -0400
@@ -260,86 +260,3 @@
 
 
 
-import java.net.ResponseCache
-import Console.err
-
-sealed trait Action
-case object Forward extends Action
-case object Backward extends Action
-case object Help extends Action
-
-object Main extends App {
-
-  def printHelp():Unit = {
-    val message =
-"""Usage:
-  java -jar [-dependencies|-impact|-help] [-local base_directory] URL1 URL2 ...
-
-Dependency tool for fragments on the W3C website.
-
-Parameters:
-  -dependencies          which URLs are dependencies of the given URLs
-  -impact                which URLs are impacted by the given URLs
-  -help                  you're using it!
-  -local base_directory  read files on the filesystem instead of dereferencing them
-
-Example:
-  java -jar fragdep.jar -local /home/betehess/W3C/ -dependencies http://www.w3.org/standards/techs/agentsecurity.html
-"""
-    println(message)
-  }
-
-  override def main(args: Array[String]):Unit = {
-
-    var action:Action = Help
-
-    // interpret parameters and returns the list of urls
-    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 command :: _ if command startsWith "-" => {
-          err.println("Unknown parameter " + command)
-          err.println("Use -help for more informations about usage")
-          sys.exit(2)
-        }
-        case _ => args
-      }
-
-    val pages:List[Page] = readArgs(args.toList) flatMap {
-      url => try {
-        Some(Page(new URL(url)))
-      } catch {
-        case e => err.println("error with " + url + ": " + e.getMessage); None
-      }
-    }
-
-    action match {
-      case Help => printHelp()
-      case Backward => {
-        val dependencies = W3C.recipes dependencies pages
-        println(dependencies.mkString(" "))
-      }
-      case Forward => {
-        val impactedPages = W3C.recipes impactedPages pages
-        println(impactedPages.mkString(" "))
-      }
-    }
-
-  }
-  
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/Main.scala	Fri Jul 29 15:22:24 2011 -0400
@@ -0,0 +1,86 @@
+package org.w3.generator
+
+import java.net.ResponseCache
+import Console.err
+import java.net.URL
+
+sealed trait Action
+case object Forward extends Action
+case object Backward extends Action
+case object Help extends Action
+
+object Main extends App {
+
+  def printHelp():Unit = {
+    val message =
+"""Usage:
+  java -jar [-dependencies|-impact|-help] [-local base_directory] URL1 URL2 ...
+
+Dependency tool for fragments on the W3C website.
+
+Parameters:
+  -dependencies          which URLs are dependencies of the given URLs
+  -impact                which URLs are impacted by the given URLs
+  -help                  you're using it!
+  -local base_directory  read files on the filesystem instead of dereferencing them
+
+Example:
+  java -jar fragdep.jar -local /home/betehess/W3C/ -dependencies http://www.w3.org/standards/techs/agentsecurity.html
+"""
+    println(message)
+  }
+
+  override def main(args: Array[String]):Unit = {
+
+    var action:Action = Help
+
+    // interpret parameters and returns the list of urls
+    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 command :: _ if command startsWith "-" => {
+          err.println("Unknown parameter " + command)
+          err.println("Use -help for more informations about usage")
+          sys.exit(2)
+        }
+        case _ => args
+      }
+
+    val pages:List[Page] = readArgs(args.toList) flatMap {
+      url => try {
+        Some(Page(new URL(url)))
+      } catch {
+        case e => err.println("error with " + url + ": " + e.getMessage); None
+      }
+    }
+
+    action match {
+      case Help => printHelp()
+      case Backward => {
+        val dependencies = W3C.recipes dependencies pages
+        println(dependencies.mkString(" "))
+      }
+      case Forward => {
+        val impactedPages = W3C.recipes impactedPages pages
+        println(impactedPages.mkString(" "))
+      }
+    }
+
+  }
+  
+}