summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2006-06-15 15:22:07 +0000
committerLex Spoon <lex@lexspoon.org>2006-06-15 15:22:07 +0000
commitca712dacc6bcd3910cc132b77f49a7e9a1c3e4cb (patch)
tree065011fd93dfb5ea7b6ccc3a5bbaad199da83fa7 /src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
parent5bae313f42a697ff2c4a55b861254764df071971 (diff)
downloadscala-ca712dacc6bcd3910cc132b77f49a7e9a1c3e4cb.tar.gz
scala-ca712dacc6bcd3910cc132b77f49a7e9a1c3e4cb.tar.bz2
scala-ca712dacc6bcd3910cc132b77f49a7e9a1c3e4cb.zip
Diffstat (limited to 'src/compiler/scala/tools/nsc/GenericRunnerCommand.scala')
-rw-r--r--src/compiler/scala/tools/nsc/GenericRunnerCommand.scala52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
new file mode 100644
index 0000000000..7fbf0d8f21
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
@@ -0,0 +1,52 @@
+package scala.tools.nsc
+
+/** A command for ScriptRunner */
+class GenericRunnerCommand(allargs: List[String], error: String=>Unit) {
+ def this(allargs: List[String]) = this(allargs, str:String => {
+ Console.println("Error: " + str)
+ })
+
+ /** Settings specified by this command */
+ val settings = new GenericRunnerSettings(error)
+
+ /** Whether the command was parsed correctly */
+ var ok = true
+
+ /** What to run. If it is None, then the interpreter should be started */
+ var thingToRun: Option[String] = None
+
+ /** Arguments to pass to the object or script to run */
+ var arguments: List[String] = Nil
+
+ private def parseArguments: Unit = {
+ var args = allargs
+
+ while (!args.isEmpty && ok && args.head.startsWith("-")) {
+ val args0 = args
+ for (val setting <- settings.allSettings)
+ args = setting.tryToSet(args)
+ if (args eq args0) {
+ error("unknown option: '" + args.head + "'")
+ ok = false
+ }
+ }
+
+ if(!args.isEmpty) {
+ thingToRun = Some(args.head)
+ arguments = args.tail
+ }
+ }
+ parseArguments
+
+ val usageMessage = {
+ "scala [ <compiler-option> | -howtorun:how ]... [<torun> <arguments>]\n" +
+ "\n" +
+ "<compiler-option>'s are as for scalac; see scalac -help.\n" +
+ "<torun>, if present, is an object or script file to run.\n" +
+ "If no <torun> is present, run an interactive interpreter.\n" +
+ "-howtorun allows explicitly specifying how to run <torun>:\n" +
+ " script: it is a script file\n" +
+ " object: it is an object name\n" +
+ " guess: (the default) try to guess\n"
+ }
+}