Skip to content

Commit b30f363

Browse files
committed
improved help message format
1 parent 819e0b1 commit b30f363

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,30 @@ object CompilerCommand {
6969

7070
/** Creates a help message for a subset of options based on cond */
7171
def availableOptionsMsg(cond: Setting[?] => Boolean): String = {
72-
val ss = (ctx.settings.allSettings filter cond).toList sortBy (_.name)
73-
val width = (ss map (_.name.length)).max
74-
def format(s: String) = ("%-" + width + "s") format s
72+
val ss = (settings.allSettings filter cond).toList sortBy (_.name)
73+
val width = (ss map (_.name.length)).max
74+
val (nameWidth, descriptionWidth) = {
75+
val maxNameWidth = 30
76+
val maxTotalWidth = 100
77+
val w = if width < maxNameWidth then width else maxNameWidth
78+
(w, maxTotalWidth - w)
79+
}
80+
def formatName(name: String) =
81+
if name.length <= nameWidth then ("%-" + nameWidth + "s") format name
82+
else (name + "\n%-" + nameWidth + "s") format ""
83+
def formatDescription(text: String): String =
84+
if text.length < descriptionWidth then text
85+
else {
86+
val inx = text.substring(0, descriptionWidth).lastIndexOf(" ")
87+
val str = text.substring(0, inx)
88+
s"${str}\n${formatName("")} ${formatDescription(text.substring(inx + 1))}"
89+
}
90+
def formatSetting(name: String, value: String) =
91+
if (value.nonEmpty)
92+
// the format here is helping to make empty padding and put the additional information exactly under the description.
93+
s"\n${formatName("")} $name: $value."
94+
else
95+
""
7596
def helpStr(s: Setting[?]) = {
7697
def defaultValue = s.default match {
7798
case _: Int | _: String => s.default.toString
@@ -80,13 +101,7 @@ object CompilerCommand {
80101
// For example 'false' for the version command.
81102
""
82103
}
83-
def formatSetting(name: String, value: String) =
84-
if (value.nonEmpty)
85-
// the format here is helping to make empty padding and put the additional information exactly under the description.
86-
s"\n${format("")} $name: $value."
87-
else
88-
""
89-
s"${format(s.name)} ${s.description}${formatSetting("Default", defaultValue)}${formatSetting("Choices", s.legalChoices)}"
104+
s"${formatName(s.name)} ${formatDescription(s.description)}${formatSetting("Default", defaultValue)}${formatSetting("Choices", s.legalChoices)}"
90105
}
91106
ss map helpStr mkString "\n"
92107
}

0 commit comments

Comments
 (0)