@@ -69,9 +69,30 @@ object CompilerCommand {
69
69
70
70
/** Creates a help message for a subset of options based on cond */
71
71
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
+ " "
75
96
def helpStr (s : Setting [? ]) = {
76
97
def defaultValue = s.default match {
77
98
case _ : Int | _ : String => s.default.toString
@@ -80,13 +101,7 @@ object CompilerCommand {
80
101
// For example 'false' for the version command.
81
102
" "
82
103
}
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)}"
90
105
}
91
106
ss map helpStr mkString " \n "
92
107
}
0 commit comments