summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-07-17 10:04:20 -0700
committerSom Snytt <som.snytt@gmail.com>2014-07-17 10:04:20 -0700
commitbde623925d011841f222891050c5fdb08f3bb251 (patch)
treed69aa258a538d59d6fddbbd6e87a9b00db8d3121 /src/compiler/scala/tools/nsc/settings/MutableSettings.scala
parentf81ec8d1f6481ddacfb27e743c6c58961e765f0e (diff)
downloadscala-bde623925d011841f222891050c5fdb08f3bb251.tar.gz
scala-bde623925d011841f222891050c5fdb08f3bb251.tar.bz2
scala-bde623925d011841f222891050c5fdb08f3bb251.zip
SI-8525 Multichoice help
Enables -Xlint:help and -language:help. The Settings API makes it difficult to innovate.
Diffstat (limited to 'src/compiler/scala/tools/nsc/settings/MutableSettings.scala')
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index 0dd4ae0b3b..8c69b49b98 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -201,7 +201,7 @@ class MutableSettings(val errorFn: String => Unit)
}
// a wrapper for all Setting creators to keep our list up to date
- private def add[T <: Setting](s: T): T = {
+ private[nsc] def add[T <: Setting](s: T): T = {
allSettings += s
s
}
@@ -552,7 +552,7 @@ class MutableSettings(val errorFn: String => Unit)
}
/** A setting that receives any combination of enumerated values,
- * including "_" to mean all values.
+ * including "_" to mean all values and "help" for verbose info.
* In non-colonated mode, stops consuming args at the first
* non-value, instead of at the next option, as for a multi-string.
*/
@@ -562,16 +562,18 @@ class MutableSettings(val errorFn: String => Unit)
descr: String,
override val choices: List[String],
val default: () => Unit
- ) extends MultiStringSetting(name, arg, s"$descr${ choices.mkString(": ", ",", ".") }") {
+ ) extends MultiStringSetting(name, s"_,$arg,-$arg", s"$descr: `_' for all, `$name:help' to list") {
- def badChoice(s: String, n: String) = errorFn(s"'$s' is not a valid choice for '$name'")
- def choosing = choices.nonEmpty
- def isChoice(s: String) = (s == "_") || (choices contains (s stripPrefix "-"))
+ private def badChoice(s: String, n: String) = errorFn(s"'$s' is not a valid choice for '$name'")
+ private def choosing = choices.nonEmpty
+ private def isChoice(s: String) = (s == "_") || (choices contains (s stripPrefix "-"))
+ private var sawHelp = false
override protected def tts(args: List[String], halting: Boolean) = {
val added = collection.mutable.ListBuffer.empty[String]
def tryArg(arg: String) = arg match {
case "_" if choosing => default()
+ case "help" if choosing => sawHelp = true
case s if !choosing || isChoice(s) => added += s
case s => badChoice(s, name)
}
@@ -586,6 +588,9 @@ class MutableSettings(val errorFn: String => Unit)
else value = added.toList // update all new settings at once
Some(rest)
}
+
+ def isHelping: Boolean = sawHelp
+ def help: String = s"$descr${ choices.mkString(":\n", " \n", "\n") }"
}
/** A setting that accumulates all strings supplied to it,