Skip to content

Commit d76229e

Browse files
author
som-snytt
authored
Merge pull request scala#10738 from som-snytt/issue/9793-bad-doc-option
Stop on erroneous doc command
2 parents 128e77b + 5f60ba2 commit d76229e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/compiler/scala/tools/nsc/Driver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class Driver {
2828

2929
/** Forward errors to the (current) reporter. */
3030
protected def scalacError(msg: String): Unit = {
31-
reporter.error(FakePos("scalac"), msg + "\n scalac -help gives more information")
31+
reporter.error(FakePos("scalac"), s"$msg\n scalac -help gives more information")
3232
}
3333

3434
/** True to continue compilation. */

src/scaladoc/scala/tools/nsc/ScalaDoc.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,38 @@ import scala.reflect.internal.util.{FakePos, Position}
2121
* that generates documentation from source files.
2222
*/
2323
class ScalaDoc {
24+
import ScalaDoc._
2425
val versionMsg = s"Scaladoc ${Properties.versionString} -- ${Properties.copyrightString}"
2526

2627
def process(args: Array[String]): Boolean = {
2728
var reporter: ScalaDocReporter = null
28-
val docSettings = new doc.Settings(msg => reporter.error(FakePos("scaladoc"), msg + "\n scaladoc -help gives more information"),
29+
val docSettings = new doc.Settings(msg => reporter.error(NoDocPos, s"$msg\n scaladoc -help gives more information"),
2930
msg => reporter.echo(msg),
3031
DefaultPathFactory)
3132
reporter = new ScalaDocReporter(docSettings)
32-
val command = new ScalaDoc.Command(args.toList, docSettings)
33+
val command = new Command(args.toList, docSettings)
3334
def hasFiles = command.files.nonEmpty || docSettings.uncompilableFiles.nonEmpty
3435

35-
if (docSettings.version.value)
36+
if (!command.ok)
37+
()
38+
else if (docSettings.version.value)
3639
reporter.echo(versionMsg)
3740
else if (docSettings.Xhelp.value)
3841
reporter.echo(command.xusageMsg)
3942
else if (docSettings.Yhelp.value)
4043
reporter.echo(command.yusageMsg)
4144
else if (docSettings.showPlugins.value)
42-
reporter.warning(null, "Plugins are not available when using Scaladoc")
45+
reporter.warning(NoDocPos, "Plugins are not available when using Scaladoc")
4346
else if (docSettings.showPhases.value)
44-
reporter.warning(null, s"Phases are restricted when using Scaladoc.\n${new DocFactory(reporter, docSettings).compiler.phaseDescriptions}")
47+
reporter.warning(NoDocPos, s"Phases are restricted when using Scaladoc.\n${new DocFactory(reporter, docSettings).compiler.phaseDescriptions}")
4548
else if (docSettings.help.value || !hasFiles)
4649
reporter.echo(command.usageMsg)
4750
else
4851
try new DocFactory(reporter, docSettings).document(command.files)
4952
catch {
5053
case ex @ FatalError(msg) =>
5154
if (docSettings.isDebug) ex.printStackTrace()
52-
reporter.error(null, "fatal error: " + msg)
55+
reporter.error(NoDocPos, s"fatal error: $msg")
5356
}
5457
finally reporter.finish()
5558

@@ -86,13 +89,14 @@ class ScalaDocReporter(settings: Settings) extends ConsoleReporter(settings) {
8689
}
8790

8891
object ScalaDoc extends ScalaDoc {
92+
val NoDocPos = FakePos("scaladoc")
93+
8994
class Command(arguments: List[String], settings: doc.Settings) extends CompilerCommand(arguments, settings) {
9095
override def cmdName = "scaladoc"
91-
override def usageMsg = (
92-
createUsageMsg("where possible scaladoc", explain = false)(x => x.isStandard && settings.isScaladocSpecific(x.name)) +
93-
"\n\nStandard scalac options also available:" +
94-
optionsMessage(x => x.isStandard && !settings.isScaladocSpecific(x.name))
95-
)
96+
override def usageMsg =
97+
sm"""${createUsageMsg("where possible scaladoc", explain = false)(x => x.isStandard && settings.isScaladocSpecific(x.name))}
98+
|Standard scalac options also available:
99+
|${optionsMessage(x => x.isStandard && !settings.isScaladocSpecific(x.name))}"""
96100
}
97101

98102
def main(args: Array[String]): Unit = {

0 commit comments

Comments
 (0)