summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-18 19:06:22 +0000
committerPaul Phillips <paulp@improving.org>2011-03-18 19:06:22 +0000
commit0554c378653c47aefaabe48b0ef568f952d1695b (patch)
treea9c8b1e004efc67a2a7cd4772ae08013e99b108a
parentf3b970b28cf640904fe0d340f9eb7de37514cb67 (diff)
downloadscala-0554c378653c47aefaabe48b0ef568f952d1695b.tar.gz
scala-0554c378653c47aefaabe48b0ef568f952d1695b.tar.bz2
scala-0554c378653c47aefaabe48b0ef568f952d1695b.zip
Improved the error message when one gives inval...
Improved the error message when one gives invalid options to scala. Similar improvements for scalac/fsc/etc has to wait. No review.
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala4
-rw-r--r--src/compiler/scala/tools/nsc/GenericRunnerCommand.scala21
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala2
3 files changed, 17 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index 2e3bc32007..1c0fd8b9de 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -17,9 +17,11 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
/** file extensions of files that the compiler can process */
lazy val fileEndings = Properties.fileEndings
- val (ok, files) =
+ private val processArgumentsResult =
if (shouldProcessArguments) processArguments
else (true, Nil)
+ def ok = processArgumentsResult._1
+ def files = processArgumentsResult._2
/** The name of the command */
def cmdName = "scalac"
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
index c8e86a752d..68689a4109 100644
--- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
+++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
@@ -27,8 +27,8 @@ extends CompilerCommand(args, settings) {
/** thingToRun: What to run. If it is None, then the interpreter should be started
* arguments: Arguments to pass to the object or script to run
*/
- val (thingToRun, arguments) = {
- val (_, remaining) = settings.processArguments(args, false)
+ val (_ok, thingToRun, arguments) = {
+ val (ok, remaining) = settings.processArguments(args, false)
val mainClass =
if (settings.jarfile.isDefault) None
else new io.Jar(settings.jarfile.value).mainClass
@@ -37,17 +37,23 @@ extends CompilerCommand(args, settings) {
// Otherwise, the first remaining argument is the program to run, and the rest
// of the arguments go to it. If remaining is empty, we'll start the repl.
mainClass match {
- case Some(name) => (Some(name), remaining)
- case _ => (remaining.headOption, remaining drop 1)
+ case Some(name) => (ok, Some(name), remaining)
+ case _ => (ok, remaining.headOption, remaining drop 1)
}
}
+ override def ok = _ok
- override def usageMsg ="""
+ private def interpolate(s: String) = s.trim.replaceAll("@cmd@", cmdName).replaceAll("@compileCmd@", compCmdName) + "\n"
+
+ def shortUsageMsg = interpolate("""
Usage: @cmd@ <options> [<script|class|object> <arguments>]
or @cmd@ <options> [-jar <jarfile> <arguments>]
+ or @cmd@ -help
-All options to @compileCmd@ are allowed. See @compileCmd@ -help.
+All options to @compileCmd@ are also allowed. See @compileCmd@ -help.
+ """)
+ override def usageMsg = shortUsageMsg + "\n" + interpolate("""
The first given argument other than options to @cmd@ designates
what to run. Runnable targets are:
@@ -74,6 +80,5 @@ A file argument will be run as a scala script unless it contains only top
level classes and objects, and exactly one runnable main method. In that
case the file will be compiled and the main method invoked. This provides
a bridge between scripts and standard scala source.
-
- """.replaceAll("@cmd@", cmdName).replaceAll("@compileCmd@", compCmdName)
+ """) + "\n"
}
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index ad7cde1e30..e40fdea3b9 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -38,7 +38,7 @@ object MainGenericRunner {
import command.settings
def sampleCompiler = new Global(settings) // def so its not created unless needed
- if (!command.ok) return errorFn("%s\n%s".format(command.usageMsg, sampleCompiler.pluginOptionsHelp))
+ if (!command.ok) return errorFn("\n" + command.shortUsageMsg)
else if (settings.version.value) return errorFn("Scala code runner %s -- %s".format(versionString, copyrightString))
else if (command.shouldStopWithInfo) return errorFn(command getInfoMessage sampleCompiler)