Skip to content

Commit fcd422a

Browse files
fedor-shiallanrenucci
authored andcommitted
Fix #4005 command-line options help is incomplete (#4018)
Fix #4005 command-line options help is incomplete - added default value output - added choices values output
1 parent ad01d69 commit fcd422a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

compiler/src/dotty/tools/dotc/config/CompilerCommand.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package dotty.tools.dotc
22
package config
33

44
import java.nio.file.{Files, Paths}
5+
56
import Settings._
67
import core.Contexts._
78
import util.DotClass
89
import Properties._
10+
911
import scala.collection.JavaConverters._
1012

1113
object CompilerCommand extends DotClass {
@@ -71,7 +73,23 @@ object CompilerCommand extends DotClass {
7173
val ss = (ctx.settings.allSettings filter cond).toList sortBy (_.name)
7274
val width = (ss map (_.name.length)).max
7375
def format(s: String) = ("%-" + width + "s") format s
74-
def helpStr(s: Setting[_]) = s"${format(s.name)} ${s.description}"
76+
def helpStr(s: Setting[_]) = {
77+
def defaultValue = s.default match {
78+
case _: Int | _: String => s.default.toString
79+
case _ =>
80+
// For now, skip the default values that do not make sense for the end user.
81+
// For example 'false' for the version command.
82+
""
83+
}
84+
def formatSetting(name: String, value: String) = {
85+
if (value.nonEmpty)
86+
// the format here is helping to make empty padding and put the additional information exactly under the description.
87+
s"\n${format("")} $name: $value."
88+
else
89+
""
90+
}
91+
s"${format(s.name)} ${s.description}${formatSetting("Default", defaultValue)}${formatSetting("Choices", s.legalChoices)}"
92+
}
7593
ss map helpStr mkString "\n"
7694
}
7795

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ object Settings {
8888
state.update(idx, x.asInstanceOf[T])
8989
}
9090

91-
def isDefaultIn(state: SettingsState) = valueIn(state) == default
91+
def isDefaultIn(state: SettingsState): Boolean = valueIn(state) == default
9292

9393
def legalChoices: String =
9494
if (choices.isEmpty) ""

0 commit comments

Comments
 (0)