summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-07-13 15:49:21 +0000
committerLex Spoon <lex@lexspoon.org>2007-07-13 15:49:21 +0000
commit6d9221f765be5c2e4d48878d08899f84ae7e0bf2 (patch)
treef096a9b9ed553d07a6f528e7a448855114063c8f /src
parent07833a931f89676a34e9b2ad8704cd14ab1a4ec9 (diff)
downloadscala-6d9221f765be5c2e4d48878d08899f84ae7e0bf2.tar.gz
scala-6d9221f765be5c2e4d48878d08899f84ae7e0bf2.tar.bz2
scala-6d9221f765be5c2e4d48878d08899f84ae7e0bf2.zip
Refactored GenericRunnerCommand to be a sublcas...
Refactored GenericRunnerCommand to be a sublcass of CompilerCommand
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala57
-rw-r--r--src/compiler/scala/tools/nsc/GenericRunnerCommand.scala23
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala24
3 files changed, 61 insertions, 43 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index 333d95d6ca..f188510eca 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -59,35 +59,44 @@ class CompilerCommand(arguments: List[String], val settings: Settings,
"\n")
}
- // initialization
- var args = arguments
+
+ /** Whether the command was processed okay */
var ok = true
- while (!args.isEmpty && ok) {
- if (args.head startsWith "-") {
- if (interactive) {
- error("no options can be given in interactive mode")
- ok = false
- } else {
- val args0 = args
- for (setting <- settings.allSettings)
- if (args eq args0)
- args = setting.tryToSet(args)
+ /** Process the arguments and update the settings accordingly.
+ This method is called only once, during initialization. */
+ protected def processArguments() {
+ // initialization
+ var args = arguments
- if (args eq args0) {
- error("bad option: '" + args.head + "'")
+ while (!args.isEmpty && ok) {
+ if (args.head startsWith "-") {
+ if (interactive) {
+ error("no options can be given in interactive mode")
ok = false
- } else
- ok = settings.checkDependencies
+ } else {
+ val args0 = args
+ for (setting <- settings.allSettings)
+ if (args eq args0)
+ args = setting.tryToSet(args)
+
+ if (args eq args0) {
+ error("bad option: '" + args.head + "'")
+ ok = false
+ } else
+ ok = settings.checkDependencies
+ }
+ } else if ((settings.script.value != "") || args.head.endsWith(fileEnding)) {
+ fs = args.head :: fs
+ args = args.tail
+ } else if (args.head.length == 0) {//quick fix
+ args = args.tail
+ } else {
+ error("don't know what to do with " + args.head)
+ ok = false
}
- } else if ((settings.script.value != "") || args.head.endsWith(fileEnding)) {
- fs = args.head :: fs
- args = args.tail
- } else if (args.head.length == 0) {//quick fix
- args = args.tail
- } else {
- error("don't know what to do with " + args.head)
- ok = false
}
}
+
+ processArguments()
}
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
index cf5e89fdf8..cb279e1290 100644
--- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
+++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
@@ -8,29 +8,29 @@
package scala.tools.nsc
/** A command for ScriptRunner */
-class GenericRunnerCommand(allargs: List[String], error: String => Unit) {
+class GenericRunnerCommand(
+ allargs: List[String],
+ override val settings: GenericRunnerSettings,
+ error: String => Unit)
+extends CompilerCommand(allargs, settings, error, false)
+{
+ def this(allargs: List[String], error: String=>Unit) =
+ this(allargs, new GenericRunnerSettings(error), error)
+
def this(allargs: List[String]) =
this(allargs, str => Console.println("Error: " + str))
- /** name of the command */
- val cmdName = "scala"
/** name of the associated compiler command */
val compCmdName = "scalac"
- /** 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 = {
+ override protected def processArguments() {
var args = allargs
while (!args.isEmpty && ok && args.head.startsWith("-")) {
@@ -49,9 +49,8 @@ class GenericRunnerCommand(allargs: List[String], error: String => Unit) {
arguments = args.tail
}
}
- parseArguments
- val usageMessage = {
+ override def usageMsg = {
cmdName + " [ <option> ]... [<torun> <arguments>]\n" +
"\n" +
"All options to "+compCmdName+" are allowed. See "+compCmdName+" -help.\n" +
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index d98abb19c6..a475a53fde 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -54,12 +54,15 @@ object MainGenericRunner {
def main(args: Array[String]) {
def error(str: String) = Console.println(str)
val command = new GenericRunnerCommand(args.toList, error)
- if (!command.ok) {
- Console.println(command.usageMessage)
- return ()
- }
val settings = command.settings
+ def sampleCompiler = new Global(settings)
+
+ if (!command.ok) {
+ println(command.usageMsg)
+ println(sampleCompiler.pluginOptionsHelp)
+ return
+ }
settings.classpath.value =
addClasspathExtras(settings.classpath.value)
@@ -74,12 +77,19 @@ object MainGenericRunner {
return
}
- if (settings.help.value || !command.ok) {
- println(command.usageMessage)
+
+ if (settings.help.value ||settings.Xhelp.value) {
+ if (command.settings.help.value) {
+ println(command.usageMsg)
+ println(sampleCompiler.pluginOptionsHelp)
+ }
+
+ if (settings.Xhelp.value)
+ println(command.xusageMsg)
+
return
}
- def sampleCompiler = new Global(settings)
if (settings.showPhases.value) {
println(sampleCompiler.phaseDescriptions)