summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/cmd
diff options
context:
space:
mode:
authorSimon Ochsenreither <simon@ochsenreither.de>2013-07-01 13:29:06 +0200
committerSimon Ochsenreither <simon@ochsenreither.de>2013-07-01 13:29:06 +0200
commitf5a18b5afaf866134a49af167db707a52044ea99 (patch)
tree9199c28bf88a73b4f4373dfbecf5495ed3662764 /src/compiler/scala/tools/cmd
parentbfda11426f9c908831489bb9173bc88dec5c4ce8 (diff)
downloadscala-f5a18b5afaf866134a49af167db707a52044ea99.tar.gz
scala-f5a18b5afaf866134a49af167db707a52044ea99.tar.bz2
scala-f5a18b5afaf866134a49af167db707a52044ea99.zip
SI-7591 Move command-line spec usage demo to tests
Diffstat (limited to 'src/compiler/scala/tools/cmd')
-rw-r--r--src/compiler/scala/tools/cmd/Demo.scala85
1 files changed, 0 insertions, 85 deletions
diff --git a/src/compiler/scala/tools/cmd/Demo.scala b/src/compiler/scala/tools/cmd/Demo.scala
deleted file mode 100644
index fc90140f8f..0000000000
--- a/src/compiler/scala/tools/cmd/Demo.scala
+++ /dev/null
@@ -1,85 +0,0 @@
-/* NEST (New Scala Test)
- * Copyright 2007-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala
-package tools
-package cmd
-
-/** A sample command specification for illustrative purposes.
- * First take advantage of the meta-options:
- *
- * // this command creates an executable runner script "demo"
- * % scala scala.tools.cmd.Demo --self-update demo
- *
- * // this one creates and sources a completion file - note backticks
- * % `./demo --bash`
- *
- * // and now you have a runner with working completion
- * % ./demo --<tab>
- * --action --defint --int
- * --bash --defstr --str
- * --defenv --self-update --unary
- *
- * The normal option configuration is plausibly self-explanatory.
- */
-trait DemoSpec extends Spec with Meta.StdOpts with Interpolation {
- lazy val referenceSpec = DemoSpec
- lazy val programInfo = Spec.Info("demo", "Usage: demo [<options>]", "scala.tools.cmd.Demo")
-
- help("""Usage: demo [<options>]""")
- heading("Unary options:")
-
- val optIsUnary = "unary" / "a unary option" --? ;
- ("action" / "a body which may be run") --> println("Hello, I am the --action body.")
-
- heading("Binary options:")
- val optopt = "str" / "an optional String" --|
- val optoptInt = ("int" / "an optional Int") . --^[Int]
- val optEnv = "defenv" / "an optional String" defaultToEnv "PATH"
- val optDefault = "defstr" / "an optional String" defaultTo "default"
- val optDefaultInt = "defint" / "an optional Int" defaultTo -1
- val optExpand = "alias" / "an option which expands" expandTo ("--int", "15")
-}
-
-object DemoSpec extends DemoSpec with Property {
- lazy val propMapper = new PropertyMapper(DemoSpec)
-
- type ThisCommandLine = SpecCommandLine
- def creator(args: List[String]) =
- new SpecCommandLine(args) {
- override def errorFn(msg: String) = { println("Error: " + msg) ; sys.exit(0) }
- }
-}
-
-class Demo(args: List[String]) extends {
- val parsed = DemoSpec(args: _*)
-} with DemoSpec with Instance {
- import java.lang.reflect._
-
- def helpMsg = DemoSpec.helpMsg
- def demoSpecMethods = this.getClass.getMethods.toList
- private def isDemo(m: Method) = (m.getName startsWith "opt") && !(m.getName contains "$") && (m.getParameterTypes.isEmpty)
-
- def demoString(ms: List[Method]) = {
- val longest = ms map (_.getName.length) max
- val formatStr = " %-" + longest + "s: %s"
- val xs = ms map (m => formatStr.format(m.getName, m.invoke(this)))
-
- xs mkString ("Demo(\n ", "\n ", "\n)\n")
- }
-
- override def toString = demoString(demoSpecMethods filter isDemo)
-}
-
-object Demo {
- def main(args: Array[String]): Unit = {
- val runner = new Demo(args.toList)
-
- if (args.isEmpty)
- println(runner.helpMsg)
-
- println(runner)
- }
-}