From 8f5b29cddd9055eef09d1c9019f2584dc06ebdbe Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Thu, 1 Sep 2016 14:44:14 +0200 Subject: Allow all settings to be helping --- src/compiler/scala/tools/nsc/CompilerCommand.scala | 2 +- src/compiler/scala/tools/nsc/settings/AbsSettings.scala | 6 ++++++ src/compiler/scala/tools/nsc/settings/MutableSettings.scala | 4 ++-- src/compiler/scala/tools/nsc/settings/ScalaSettings.scala | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 9b8e9fa330..3879d7b425 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -107,7 +107,7 @@ class CompilerCommand(arguments: List[String], val settings: Settings) { else { val sb = new StringBuilder allSettings foreach { - case s: MultiChoiceSetting[_] if s.isHelping => sb append s.help + case s if s.isHelping => sb append s.help case _ => } sb.toString diff --git a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala index 060a24d8d4..08fa56d8e9 100644 --- a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala @@ -88,6 +88,12 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings { /** Issue error and return */ def errorAndValue[T](msg: String, x: T): T = { errorFn(msg) ; x } + /** If this method returns true, print the [[help]] message and exit. */ + def isHelping: Boolean = false + + /** The help message to be printed if [[isHelping]]. */ + def help: String = "" + /** After correct Setting has been selected, tryToSet is called with the * remainder of the command line. It consumes any applicable arguments and * returns the unconsumed ones. diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index 9cc8faf8c2..45b21f6126 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -748,9 +748,9 @@ class MutableSettings(val errorFn: String => Unit) def contains(choice: domain.Value): Boolean = value contains choice - def isHelping: Boolean = sawHelp + override def isHelping: Boolean = sawHelp - def help: String = { + override def help: String = { val choiceLength = choices.map(_.length).max + 1 val formatStr = s" %-${choiceLength}s %s" choices.zipAll(descriptions, "", "").map { diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index dae8539c66..6a164f0e1d 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -38,8 +38,8 @@ trait ScalaSettings extends AbsScalaSettings /** If any of these settings is enabled, the compiler should print a message and exit. */ def infoSettings = List[Setting](version, help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph) - /** Any -multichoice:help? Nicer if any option could report that it had help to offer. */ - private def multihelp = allSettings exists { case s: MultiChoiceSetting[_] => s.isHelping case _ => false } + /** Any -option:help? */ + private def multihelp = allSettings exists { case s => s.isHelping case _ => false } /** Is an info setting set? */ def isInfo = (infoSettings exists (_.isSetByUser)) || multihelp -- cgit v1.2.3