summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/cmd/Spec.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-04-11 00:32:00 +0000
committerPaul Phillips <paulp@improving.org>2010-04-11 00:32:00 +0000
commite93c1a93a2c8a40265b34bb9f1dd61b9470c908d (patch)
treeb9f13ffbe1d1ef59380e32f74380f9797b7fd2cb /src/compiler/scala/tools/cmd/Spec.scala
parent71b6aca681ab697304590a96b13847b9bba141dc (diff)
downloadscala-e93c1a93a2c8a40265b34bb9f1dd61b9470c908d.tar.gz
scala-e93c1a93a2c8a40265b34bb9f1dd61b9470c908d.tar.bz2
scala-e93c1a93a2c8a40265b34bb9f1dd61b9470c908d.zip
Introduces scala.tools.cmd providing command li...
Introduces scala.tools.cmd providing command line tool infrastructure. For a quick look at what can be done, see scala.tools.cmd.Demo For a more involved, potentially eye-straining look, see scala.tools.partest.PartestSpec To experience it through the eyes of Joe Partest User, run test/partest Review by community.
Diffstat (limited to 'src/compiler/scala/tools/cmd/Spec.scala')
-rw-r--r--src/compiler/scala/tools/cmd/Spec.scala45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/cmd/Spec.scala b/src/compiler/scala/tools/cmd/Spec.scala
new file mode 100644
index 0000000000..c8283165d9
--- /dev/null
+++ b/src/compiler/scala/tools/cmd/Spec.scala
@@ -0,0 +1,45 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2010 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools
+package cmd
+
+/** This trait works together with others in scala.tools.cmd to allow
+ * declaratively specifying a command line program, with many attendant
+ * benefits. See scala.tools.cmd.DemoSpec for an example.
+ */
+trait Spec {
+ def referenceSpec: Reference
+ def programInfo: Spec.Names
+
+ protected def help(str: => String): Unit
+ protected def heading(str: => String): Unit = help("\n " + str)
+
+ type OptionMagic <: Opt.Implicit
+ protected implicit def optionMagicAdditions(s: String): OptionMagic
+}
+
+object Spec {
+ case class Names(runner: String, mainClass: String) { }
+
+ class Accumulator[T: FromString]() {
+ private var _buf: List[T] = Nil
+
+ def convert(s: String) = implicitly[FromString[T]] apply s
+ def apply(s: String): T = returning(convert(s))(_buf +:= _)
+
+ lazy val get = _buf
+ }
+
+ class Choices[T: FromString](val xs: List[T]) {
+ def fs: FromString[T] = implicitly[FromString[T]]
+ def contains(x: T) = xs contains x
+ override def toString = xs.mkString("{ ", ", ", " }")
+ }
+
+ class EnvironmentVar(val name: String) {
+ override def toString = "${%s}" format name
+ }
+}