From 7578c37d9dc51f00b81bce296b276941d212986d Mon Sep 17 00:00:00 2001 From: Fedor Shiriaev Date: Tue, 20 Feb 2018 11:34:04 +0100 Subject: [PATCH 1/4] Fix #4005 command-line options help is incomplete - added default value output - added choices values output --- .../src/dotty/tools/dotc/config/CompilerCommand.scala | 9 ++++++++- compiler/src/dotty/tools/dotc/config/Settings.scala | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala index 97649426c007..8737c37e3815 100644 --- a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala +++ b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala @@ -71,7 +71,14 @@ object CompilerCommand extends DotClass { val ss = (ctx.settings.allSettings filter cond).toList sortBy (_.name) val width = (ss map (_.name.length)).max def format(s: String) = ("%-" + width + "s") format s - def helpStr(s: Setting[_]) = s"${format(s.name)} ${s.description}" + def formatSettings(name: String, value: String) = if (value.nonEmpty) format("\n") ++ s" $name: $value." else "" + def helpStr(s: Setting[_]) = { + val help = StringBuilder.newBuilder + help.append(s"${format(s.name)} ${s.description}") + help.append(formatSettings("Default", s.defaultValue)) + help.append(formatSettings("Choices", s.legalChoices)) + help.toString + } ss map helpStr mkString "\n" } diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index 66695e14d984..aa2e3ee223c1 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -88,7 +88,13 @@ object Settings { state.update(idx, x.asInstanceOf[T]) } - def isDefaultIn(state: SettingsState) = valueIn(state) == default + def isDefaultIn(state: SettingsState): Boolean = valueIn(state) == default + + def defaultValue: String = implicitly[ClassTag[T]] match { + case StringTag => default.asInstanceOf[String] + case IntTag => default.asInstanceOf[Int].toString + case _ => "" + } def legalChoices: String = if (choices.isEmpty) "" From f169cbd0c5813bf39d550f78d950554b314d02b8 Mon Sep 17 00:00:00 2001 From: Fedor Shiriaev Date: Thu, 22 Feb 2018 12:19:24 +0100 Subject: [PATCH 2/4] Erase the string builder and use the 's' string formatter for all additional settings. --- .../dotty/tools/dotc/config/CompilerCommand.scala | 15 ++++++++------- .../src/dotty/tools/dotc/config/Settings.scala | 5 ++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala index 8737c37e3815..e0ea64bb3392 100644 --- a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala +++ b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala @@ -71,14 +71,15 @@ object CompilerCommand extends DotClass { val ss = (ctx.settings.allSettings filter cond).toList sortBy (_.name) val width = (ss map (_.name.length)).max def format(s: String) = ("%-" + width + "s") format s - def formatSettings(name: String, value: String) = if (value.nonEmpty) format("\n") ++ s" $name: $value." else "" - def helpStr(s: Setting[_]) = { - val help = StringBuilder.newBuilder - help.append(s"${format(s.name)} ${s.description}") - help.append(formatSettings("Default", s.defaultValue)) - help.append(formatSettings("Choices", s.legalChoices)) - help.toString + def formatSettings(name: String, value: String) = { + if (value.nonEmpty) + // the format here is helping to make empty padding and put the additional information exactly under the description. + s"\n${format("")} $name: $value." + else + "" } + def helpStr(s: Setting[_]) = + s"${format(s.name)} ${s.description} ${formatSettings("Default", s.defaultValue)} ${formatSettings("Choices", s.legalChoices)}" ss map helpStr mkString "\n" } diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index aa2e3ee223c1..593dfba342cb 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -93,7 +93,10 @@ object Settings { def defaultValue: String = implicitly[ClassTag[T]] match { case StringTag => default.asInstanceOf[String] case IntTag => default.asInstanceOf[Int].toString - case _ => "" + case _ => + // For now, skip the default values that do not make sense for the user of course. + // For example 'false' for the version command. + "" } def legalChoices: String = From a2a0a0d50ad59de182cc5b8a981dbdafc3c5b578 Mon Sep 17 00:00:00 2001 From: Fedor Shiriaev Date: Thu, 22 Feb 2018 19:26:11 +0100 Subject: [PATCH 3/4] Move defaultValue and formatSetting helpers under the helpStr. Refactor default value from cast to match. --- .../tools/dotc/config/CompilerCommand.scala | 26 +++++++++++++------ .../dotty/tools/dotc/config/Settings.scala | 9 ------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala index e0ea64bb3392..f233bc4892e0 100644 --- a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala +++ b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala @@ -2,10 +2,12 @@ package dotty.tools.dotc package config import java.nio.file.{Files, Paths} + import Settings._ import core.Contexts._ import util.DotClass import Properties._ + import scala.collection.JavaConverters._ object CompilerCommand extends DotClass { @@ -71,15 +73,23 @@ object CompilerCommand extends DotClass { val ss = (ctx.settings.allSettings filter cond).toList sortBy (_.name) val width = (ss map (_.name.length)).max def format(s: String) = ("%-" + width + "s") format s - def formatSettings(name: String, value: String) = { - if (value.nonEmpty) - // the format here is helping to make empty padding and put the additional information exactly under the description. - s"\n${format("")} $name: $value." - else - "" + def helpStr(s: Setting[_]) = { + def defaultValue(setting: Setting[_]) = setting.default match { + case _: Int | _: String => s.default.toString + case _ => + // For now, skip the default values that do not make sense for the end user. + // For example 'false' for the version command. + "" + } + def formatSetting(name: String, value: String) = { + if (value.nonEmpty) + // the format here is helping to make empty padding and put the additional information exactly under the description. + s"\n${format("")} $name: $value." + else + "" + } + s"${format(s.name)} ${s.description} ${formatSetting("Default", defaultValue(s))} ${formatSetting("Choices", s.legalChoices)}" } - def helpStr(s: Setting[_]) = - s"${format(s.name)} ${s.description} ${formatSettings("Default", s.defaultValue)} ${formatSettings("Choices", s.legalChoices)}" ss map helpStr mkString "\n" } diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index 593dfba342cb..6343341b29f4 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -90,15 +90,6 @@ object Settings { def isDefaultIn(state: SettingsState): Boolean = valueIn(state) == default - def defaultValue: String = implicitly[ClassTag[T]] match { - case StringTag => default.asInstanceOf[String] - case IntTag => default.asInstanceOf[Int].toString - case _ => - // For now, skip the default values that do not make sense for the user of course. - // For example 'false' for the version command. - "" - } - def legalChoices: String = if (choices.isEmpty) "" else choices match { From fab4c4ff82175e420975b588b98cac48a1e23372 Mon Sep 17 00:00:00 2001 From: Fedor Shiriaev Date: Mon, 26 Feb 2018 19:13:04 +0100 Subject: [PATCH 4/4] Remove unused param from defaultValue call. Remove extra spaces from the cmd help string --- compiler/src/dotty/tools/dotc/config/CompilerCommand.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala index f233bc4892e0..591021f19275 100644 --- a/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala +++ b/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala @@ -74,7 +74,7 @@ object CompilerCommand extends DotClass { val width = (ss map (_.name.length)).max def format(s: String) = ("%-" + width + "s") format s def helpStr(s: Setting[_]) = { - def defaultValue(setting: Setting[_]) = setting.default match { + def defaultValue = s.default match { case _: Int | _: String => s.default.toString case _ => // For now, skip the default values that do not make sense for the end user. @@ -88,7 +88,7 @@ object CompilerCommand extends DotClass { else "" } - s"${format(s.name)} ${s.description} ${formatSetting("Default", defaultValue(s))} ${formatSetting("Choices", s.legalChoices)}" + s"${format(s.name)} ${s.description}${formatSetting("Default", defaultValue)}${formatSetting("Choices", s.legalChoices)}" } ss map helpStr mkString "\n" }