+ def hg statusprintHelp()
authorAlexandre Bertails <bertails@w3.org>
Fri, 29 Jul 2011 15:20:35 -0400
changeset 13 2ef59024b47f
parent 12 6a9484c1131d
child 14 c95e62f4f343
+ def hg statusprintHelp()
src/main/scala/FragmentDependencies.scala
--- a/src/main/scala/FragmentDependencies.scala	Fri Jul 29 14:08:16 2011 -0400
+++ b/src/main/scala/FragmentDependencies.scala	Fri Jul 29 15:20:35 2011 -0400
@@ -166,9 +166,6 @@
 
 }
 
-
-
-
 /** a sequence of recipes */
 case class Recipes(val recipes:Seq[Recipe]) {
 
@@ -203,14 +200,6 @@
   def make(urls:Seq[String]):Recipes = {
     val docs = XMLdocs(urls)
 
-    // val pages:Seq[Page] =
-    //   for {
-    //     (urlXML, xml) <- docs
-    //     uriList <- xml \ "uriList"
-    //     uri = uriList.attrs get "src" getOrElse error("no src in <uriList> for " + urlXML)
-    //     page <- Page(uri).extractPages
-    //   } yield page
-
     val recipes:Seq[Recipe] =
       docs flatMap { case(url, xml) => Recipe.fromXML(xml, Some(url)) }
     
@@ -272,6 +261,7 @@
 
 
 import java.net.ResponseCache
+import Console.err
 
 sealed trait Action
 case object Forward extends Action
@@ -280,11 +270,30 @@
 
 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 = {
 
-    // by default, we compute backward dependencies
-    var action:Action = Backward
+    var action:Action = Help
 
+    // interpret parameters and returns the list of urls
     def readArgs(args:List[String]):List[String] =
       args match {
         case "-dependencies" :: remainingArgs => {
@@ -303,19 +312,30 @@
           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 = readArgs(args.toList)
+    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 => println("blah")
+      case Help => printHelp()
       case Backward => {
-        val dependencies = W3C.recipes.dependencies(pages map ( Page(_) ))
+        val dependencies = W3C.recipes dependencies pages
         println(dependencies.mkString(" "))
       }
       case Forward => {
-        val impactedPages = W3C.recipes.impactedPages(pages map ( Page(_) ))
+        val impactedPages = W3C.recipes impactedPages pages
         println(impactedPages.mkString(" "))
       }
     }