Commits

Tatsuo Ikeda committed 1714855

add-scala

  • Participants
  • Parent commits 8ddf7ce
  • Branches add-scala

Comments (0)

Files changed (1)

File lib/vetags/lang/scala/createtags-scala

+#!/bin/sh
+exec scala -deprecation "$0" "$@"
+!#
+
+val PRODUCT: String = "createtags-scala"
+val VERSION: String = "0.1"
+val versionMessage = PRODUCT + " " + VERSION
+
+val helpMessage = """
+Usage: """ + PRODUCT + """ [OPTION...] [PATH]
+
+Options::
+
+  -h                   --help                                show this help message and exit.
+  -v                   --version                             output the version number.
+  -a                   --all                                 all in virtualenv packages. ignore all options.
+  -p PACKAGES          --packages=PACKAGES                   give packages name. default is a `haskell` package.
+  -s STANDARDPACKAGES  --standard-packages=STANDARDPACKAGES  give packages name. for the standard library.
+                       --no-sbt                              not include the sbt library.
+                       --allow-testcode                      include the test code.
+"""
+
+case class Args(newLine: Boolean, repeat: Int, message: String)
+
+def parseArgs(args: List[String]): Option[Args] = {
+
+  var newLine = true
+  var repeat = 1
+  var help = false
+
+  @scala.annotation.tailrec
+  def parseArgsHelper(args: List[String]): Args = {
+    args match {
+      case "-a" :: rest => {
+        newLine = false
+        parseArgsHelper(rest)
+      }
+
+      case "-p" :: x :: rest => {
+        repeat = x.toInt
+        parseArgsHelper(rest)
+      }
+
+      case ("-h" | "--help") :: rest => {
+        Console.println(helpMessage)
+        sys.exit(0)
+      }
+
+      case ("-v" | "--version") :: rest => {
+        Console.println(versionMessage)
+        sys.exit(0)
+      }
+
+      case message =>
+        Args(newLine, repeat, message.mkString(" "))
+    }
+  }
+
+  try { Some(parseArgsHelper(args)) } catch { case _ =>  None }
+
+}
+
+def __(args: Args): Unit = args match {
+  case Args(true, repeat, message) => (1 to repeat) foreach { _ => println(message) }
+  case Args(false, repeat, message) => (1 to repeat) foreach { _ => print(message) }
+}
+
+def main = parseArgs(args.toList) match {
+  case Some(args) => __(args)
+  case None => println("Invalid Arguments!")
+}
+
+main
+
+
+
+// vim: set et fenc= ft=scala ff=unix sts=0 sw=2 ts=2 :