Skip to content

Commit

Permalink
Issue 435 & 436: Included Files With Syntax Errors Yield Tacit Success (
Browse files Browse the repository at this point in the history
#437)

* Improvements for issue 435

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

* ANSI Colorized messages with full path on a line

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

* Enhance the Issue 435 test case, highlight Logger prefix too

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

* Deal with failing test cases relying on no highlighting

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

---------

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Sep 22, 2023
1 parent c2164af commit fbf550b
Show file tree
Hide file tree
Showing 41 changed files with 727 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import scopt.OParser

import java.nio.file.Path

/** Base class for command options. Every command should extend this to a case
* class
/** Base class for command options. Every command should extend this to a case class
*/
trait CommandOptions {
def command: String
Expand Down Expand Up @@ -73,8 +72,7 @@ object CommandOptions {
objCur: ConfigObjectCursor,
key: String,
default: T
)(mapIt: ConfigCursor => ConfigReader.Result[T]
): ConfigReader.Result[T] = {
)(mapIt: ConfigCursor => ConfigReader.Result[T]): ConfigReader.Result[T] = {
objCur.atKeyOrUndefined(key) match {
case stCur if stCur.isUndefined => Right[ConfigReaderFailures, T](default)
case stCur => mapIt(stCur)
Expand All @@ -83,90 +81,99 @@ object CommandOptions {

private def noBool = Option.empty[Boolean]

implicit val commonOptionsReader: ConfigReader[CommonOptions] = {
(cur: ConfigCursor) =>
{
for
topCur <- cur.asObjectCursor
topRes <- topCur.atKey("common")
objCur <- topRes.asObjectCursor
showTimes <-
optional[Boolean](objCur, "show-times", false)(c => c.asBoolean)
verbose <- optional(objCur, "verbose", false)(cc => cc.asBoolean)
dryRun <- optional(objCur, "dry-run", false)(cc => cc.asBoolean)
quiet <- optional(objCur, "quiet", false)(cc => cc.asBoolean)
debug <- optional(objCur, "debug", false)(cc => cc.asBoolean)
sortMessages <- optional(objCur, "sort-messages-by-location", noBool)(
cc => cc.asBoolean.map(Option(_))
)
suppressWarnings <- optional(objCur, "suppress-warnings", noBool)(
cc => cc.asBoolean.map(Option(_))
)
suppressStyleWarnings <-
optional(objCur, "suppress-style-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
suppressMissingWarnings <-
optional(objCur, "suppress-missing-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
hideWarnings <- optional(objCur, "hide-warnings", noBool)(cc =>
implicit val commonOptionsReader: ConfigReader[CommonOptions] = { (cur: ConfigCursor) =>
{
for
topCur <- cur.asObjectCursor
topRes <- topCur.atKey("common")
objCur <- topRes.asObjectCursor
showTimes <-
optional[Boolean](objCur, "show-times", false)(c => c.asBoolean)
verbose <- optional(objCur, "verbose", false)(cc => cc.asBoolean)
dryRun <- optional(objCur, "dry-run", false)(cc => cc.asBoolean)
quiet <- optional(objCur, "quiet", false)(cc => cc.asBoolean)
debug <- optional(objCur, "debug", false)(cc => cc.asBoolean)
noANSIMessages <- optional(objCur, "noANSIMessages", false)(cc => cc.asBoolean)
sortMessages <- optional(objCur, "sort-messages-by-location", noBool)(cc => cc.asBoolean.map(Option(_)))
suppressWarnings <- optional(objCur, "suppress-warnings", noBool)(cc => cc.asBoolean.map(Option(_)))
suppressStyleWarnings <-
optional(objCur, "suppress-style-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
)
hideStyleWarnings <- optional(objCur, "hide-style-warnings", noBool) {
cc => cc.asBoolean.map(Option(_))
}
hideMissingWarnings <-
optional(objCur, "hide-missing-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
showWarnings <- optional(objCur, "show-warnings", noBool) { cc =>
suppressMissingWarnings <-
optional(objCur, "suppress-missing-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
showStyleWarnings <- optional(objCur, "show-style-warnings", noBool) {
cc => cc.asBoolean.map(Option(_))
hideWarnings <- optional(objCur, "hide-warnings", noBool)(cc => cc.asBoolean.map(Option(_)))
hideStyleWarnings <- optional(objCur, "hide-style-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
hideMissingWarnings <-
optional(objCur, "hide-missing-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
showMissingWarnings <-
optional(objCur, "show-missing-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
showUnusedWarnings <-
optional(objCur, "show-unused-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
pluginsDir <- optional(objCur, "plugins-dir", Option.empty[Path]) {
cc => cc.asString.map(f => Option(Path.of(f)))
showWarnings <- optional(objCur, "show-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
showStyleWarnings <- optional(objCur, "show-style-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
showMissingWarnings <-
optional(objCur, "show-missing-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
yield {
val default = CommonOptions()
val shouldShowWarnings = suppressWarnings.map(!_)
.getOrElse(hideWarnings.map(!_).getOrElse(showWarnings.getOrElse(
default.showWarnings
)))
val shouldShowMissing = suppressMissingWarnings.map(!_)
.getOrElse(hideMissingWarnings.map(!_).getOrElse(
showMissingWarnings.getOrElse(default.showMissingWarnings)
))
val shouldShowStyle = suppressStyleWarnings.map(!_).getOrElse(
hideStyleWarnings.map(!_)
.getOrElse(showStyleWarnings.getOrElse(default.showStyleWarnings))
showUnusedWarnings <-
optional(objCur, "show-unused-warnings", noBool) { cc =>
cc.asBoolean.map(Option(_))
}
pluginsDir <- optional(objCur, "plugins-dir", Option.empty[Path]) { cc =>
cc.asString.map(f => Option(Path.of(f)))
}
yield {
val default = CommonOptions()
val shouldShowWarnings = suppressWarnings
.map(!_)
.getOrElse(
hideWarnings
.map(!_)
.getOrElse(
showWarnings.getOrElse(
default.showWarnings
)
)
)
CommonOptions(
showTimes,
verbose,
dryRun,
quiet,
shouldShowWarnings,
shouldShowMissing,
shouldShowStyle,
showUsageWarnings = showUnusedWarnings
.getOrElse(default.showStyleWarnings),
debug,
pluginsDir,
sortMessagesByLocation = sortMessages.getOrElse(false)
val shouldShowMissing = suppressMissingWarnings
.map(!_)
.getOrElse(
hideMissingWarnings
.map(!_)
.getOrElse(
showMissingWarnings.getOrElse(default.showMissingWarnings)
)
)
}
val shouldShowStyle = suppressStyleWarnings
.map(!_)
.getOrElse(
hideStyleWarnings
.map(!_)
.getOrElse(showStyleWarnings.getOrElse(default.showStyleWarnings))
)
CommonOptions(
showTimes,
verbose,
dryRun,
quiet,
shouldShowWarnings,
shouldShowMissing,
shouldShowStyle,
showUsageWarnings = showUnusedWarnings
.getOrElse(default.showStyleWarnings),
debug,
pluginsDir,
sortMessagesByLocation = sortMessages.getOrElse(false)
)
}
}
}

final def loadCommonOptions(
Expand All @@ -179,10 +186,13 @@ object CommandOptions {
println(toPrettyString(options, 1, Some("Loaded common options:")))
}
Right(options)
case Left(failures) => Left(errors(
s"Failed to load options from $path because:\n" +
failures.prettyPrint(1)
))
case Left(failures) =>
Left(
errors(
s"Failed to load options from $path because:\n" +
failures.prettyPrint(1)
)
)
}
}

Expand All @@ -192,7 +202,8 @@ object CommandOptions {
require(args.nonEmpty)
val result = CommandPlugin.loadCommandNamed(args.head)
result match {
case Right(cmd) => cmd.parseOptions(args) match {
case Right(cmd) =>
cmd.parseOptions(args) match {
case Some(options) => Right(options)
case None => Left(errors("Option parsing failed"))
}
Expand All @@ -203,7 +214,7 @@ object CommandOptions {
val commandOptionsParser: OParser[Unit, CommandOptions] = {
val plugins = Plugin.loadPluginsFrom[CommandPlugin[CommandOptions]]()
val list =
for plugin <- plugins yield { plugin.pluginName -> plugin.getOptions }
for plugin <- plugins yield { plugin.pluginName -> plugin.getOptions }
val parsers = list.sortBy(_._1).map(_._2._1) // alphabetize
OParser.sequence(parsers.head, parsers.tail*)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,61 @@ object CommonOptionsHelper {
OParser.sequence(
programName("riddlc"),
head(blurb),
opt[Unit]('t', name = "show-times").optional()
opt[Unit]('t', name = "show-times")
.optional()
.action((_, c) => c.copy(showTimes = true))
.text("Show compilation phase execution times "),
opt[Unit]('d', "dry-run").optional()
opt[Unit]('d', "dry-run")
.optional()
.action((_, c) => c.copy(dryRun = true))
.text("go through the motions but don't write any changes"),
opt[Unit]('v', "verbose").optional()
opt[Unit]('v', "verbose")
.optional()
.action((_, c) => c.copy(verbose = true))
.text("Provide verbose output detailing riddlc's actions"),
opt[Unit]('D', "debug").optional().action((_, c) => c.copy(debug = true))
opt[Unit]('D', "debug")
.optional()
.action((_, c) => c.copy(debug = true))
.text("Enable debug output. Only useful for riddlc developers"),
opt[Unit]('q', "quiet").optional().action((_, c) => c.copy(quiet = true))
opt[Unit]('q', "quiet")
.optional()
.action((_, c) => c.copy(quiet = true))
.text("Do not print out any output, just do the requested command"),
opt[Unit]('w', name = "suppress-warnings").optional().action((_, c) =>
c.copy(
showWarnings = false,
showMissingWarnings = false,
showStyleWarnings = false,
showUsageWarnings = false
)
).text("Suppress all warning messages so only errors are shown"),
opt[Unit]('m', name = "suppress-missing-warnings").optional()
opt[Unit]('a', "noANSIMessages")
.optional()
.action((_, c) => c.copy(noANSIMessages = true))
.text("Do not print messages with ANSI formatting"),
opt [Unit] ('w', name = "suppress-warnings")
.optional()
.action((_, c) =>
c.copy(
showWarnings = false,
showMissingWarnings = false,
showStyleWarnings = false,
showUsageWarnings = false
)
)
.text("Suppress all warning messages so only errors are shown"),
opt[Unit]('m', name = "suppress-missing-warnings")
.optional()
.action((_, c) => c.copy(showMissingWarnings = false))
.text("Show warnings about things that are missing"),
opt[Unit]('s', name = "suppress-style-warnings").optional()
opt[Unit]('s', name = "suppress-style-warnings")
.optional()
.action((_, c) => c.copy(showStyleWarnings = false))
.text("Show warnings about questionable input style. "),
opt[Unit]('u', name = "suppress-unused-warnings").optional()
opt[Unit]('u', name = "suppress-unused-warnings")
.optional()
.action((_, c) => c.copy(showUsageWarnings = false))
.text("Show warnings about questionable input style. "),
opt[File]('P', name = "plugins-dir").optional()
opt[File]('P', name = "plugins-dir")
.optional()
.action((file, c) => c.copy(pluginsDir = Some(file.toPath)))
.text("Load riddlc command extension plugins from this directory."),
opt[Boolean]('S', name = "sort-warnings-by-location").optional()
.action((_, c) => c.copy(sortMessagesByLocation = true)).text(
opt[Boolean]('S', name = "sort-warnings-by-location")
.optional()
.action((_, c) => c.copy(sortMessagesByLocation = true))
.text(
"Print all messages sorted by the file name and line number in which they occur."
)
)
Expand Down
4 changes: 2 additions & 2 deletions hugo/src/test/input/regressions/match-error.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ domain PersonalBanking is {
epic CreateAccount is {
user Member wants to "establish an account" so that "they can apply for a loan"
case HappyPath {
step output PersonalBanking.PersonalBankingApp.Test.HomePage.AccountDetailsPage
"is shown to" user PersonalBanking.Member
step show output PersonalBanking.PersonalBankingApp.Test.HomePage.AccountDetailsPage
to user PersonalBanking.Member
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ case class CommonOptions(
debug: Boolean = false,
pluginsDir: Option[Path] = None,
sortMessagesByLocation: Boolean = false,
groupMessagesByKind: Boolean = true
groupMessagesByKind: Boolean = true,
noANSIMessages: Boolean = false,
)

object CommonOptions {
Expand Down
Loading

0 comments on commit fbf550b

Please sign in to comment.