Skip to content

Commit

Permalink
Change the name of an option to conform to pattern used by other opti…
Browse files Browse the repository at this point in the history
…ons. (#679)

The --no-ansi-messages is now accepted for noAnsiMessages field in Common Options

Also:
* Install headers via headerCreate
* Fix the cause of --no-ansi-messages being ignored
* The cause was not using the PlatformContext.withOptions utility in Commands.runMain and other 
   PlatformContext instances asserting themselves in other code.

Other changes getting there:
* Provide a test case for --no-ansi-messages
* Fix the logger to get highlighting setting from PlatformContext not its constructor.
* Remove all duplicate `given`s so confusion doesn't ensue
* Use CommonOptions.default when the logic is default, not empty
* Fix many scaladoc class references
* Convert all use of PlatformContext.setOptions to `withOptions`
  to encapsulate the use of the option setting
* Remove all uses of `PlatformContext.setOptions` and the implementation
* Make a `PlatformContext.withLogger` method for similar reasons and
  use it in placess the logger needs to change (mostly test cases)
* Clean up unused imports
* Make use of AbstractTestingBasis in more places
* Eliminate remaining package objects deferring to utils one
* Eliminate PlatformContext `given`s in test code
* Don't instantiate CommonOptions as much, use static values
* Cleanup PlatformContext
* Remove unused InMemoryLogger, redundant with StringLogger
* Re-enable Test parallel execution
* Clean up imports
* Fix bug in withOptions
* Remove pc.withOptiosn from top level of test suites
  • Loading branch information
reid-spencer authored Oct 27, 2024
1 parent 24ec199 commit ca43c02
Show file tree
Hide file tree
Showing 182 changed files with 1,317 additions and 542 deletions.
31 changes: 18 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import org.scoverage.coveralls.Imports.CoverallsKeys.coverallsTokenFile
import com.ossuminc.sbt.{CrossModule, DocSite, OssumIncPlugin, Plugin}
import com.typesafe.tools.mima.core.{ProblemFilters, ReversedMissingMethodProblem}
import de.heikoseeberger.sbtheader.License.ALv2
import de.heikoseeberger.sbtheader.LicenseStyle
import de.heikoseeberger.sbtheader.LicenseStyle.SpdxSyntax
import sbt.Append.{appendSeqImplicit, appendSet}
import sbt.Keys.{description, libraryDependencies}
import sbtbuildinfo.BuildInfoPlugin.autoImport.buildInfoPackage
Expand All @@ -13,11 +16,12 @@ Global / onChangedBuildSource := ReloadOnSourceChanges
enablePlugins(OssumIncPlugin)

lazy val startYear: Int = 2019
lazy val license = ALv2(yyyy = "2019-2025", copyrightOwner = "Ossum Inc.", licenseStyle = SpdxSyntax)

def cpDep(cp: CrossProject): CrossClasspathDependency = cp % "compile->compile;test->test"
def pDep(p: Project): ClasspathDependency = p % "compile->compile;test->test"

lazy val riddl: Project = Root("riddl", startYr = startYear)
lazy val riddl: Project = Root("riddl", startYr = startYear /*, license = "Apache-2.0" */ )
.configure(With.noPublishing, With.git, With.dynver, With.noMiMa)
.aggregate(
utils,
Expand All @@ -40,7 +44,7 @@ lazy val riddl: Project = Root("riddl", startYr = startYear)

lazy val Utils = config("utils")
lazy val utils_cp: CrossProject = CrossModule("utils", "riddl-utils")(JVM, JS)
.configure(With.typical)
.configure(With.typical, With.headerLicense("Apache-2.0"))
.configure(With.build_info)
.settings(
scalacOptions += "-explain-cyclic",
Expand Down Expand Up @@ -85,10 +89,11 @@ lazy val utilsJS = utils_cp.js
val Language = config("language")
lazy val language_cp: CrossProject = CrossModule("language", "riddl-language")(JVM, JS)
.dependsOn(cpDep(utils_cp))
.configure(With.typical)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.settings(
description := "Abstract Syntax Tree and basic RIDDL language parser",
scalacOptions ++= Seq("-explain", "--explain-types", "--explain-cyclic", "--no-warnings")
scalacOptions ++= Seq("-explain", "--explain-types", "--explain-cyclic", "--no-warnings"),
Test / parallelExecution := true
)
.jvmConfigure(With.coverage(65))
.jvmConfigure(With.publishing)
Expand Down Expand Up @@ -123,7 +128,7 @@ lazy val languageJS = language_cp.js.dependsOn(utilsJS)
val Passes = config("passes")
lazy val passes_cp = CrossModule("passes", "riddl-passes")(JVM, JS)
.dependsOn(cpDep(utils_cp), cpDep(language_cp))
.configure(With.typical, With.publishing)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.settings(
Test / parallelExecution := false,
scalacOptions ++= Seq("-explain", "--explain-types", "--explain-cyclic"),
Expand Down Expand Up @@ -153,7 +158,7 @@ val passes = passes_cp.jvm
val passesJS = passes_cp.js

lazy val testkit_cp = CrossModule("testkit", "riddl-testkit")(JVM, JS)
.configure(With.typical, With.publishing)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.settings(
description := "Testing kit for RIDDL language and passes"
)
Expand All @@ -174,7 +179,7 @@ val testkitJS = testkit_cp.js
val Diagrams = config("diagrams")
lazy val diagrams_cp: CrossProject = CrossModule("diagrams", "riddl-diagrams")(JVM, JS)
.dependsOn(cpDep(utils_cp), cpDep(language_cp), cpDep(passes_cp))
.configure(With.typical, With.publishing)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.settings(
description := "Implementation of various AST diagrams passes other libraries may use"
)
Expand All @@ -191,10 +196,11 @@ val diagramsJS = diagrams_cp.js
val Command = config("command")
lazy val command = Module("command", "riddl-command")
.configure(With.typical, With.coverage(30), With.MiMa("0.52.1"))
.configure(With.publishing)
.configure(With.publishing, With.headerLicense("Apache-2.0"))
.settings(
coverageExcludedPackages := "<empty>;$anon",
description := "Command infrastructure needed to define a command",
Test / parallelExecution := false,
libraryDependencies ++= Seq(
Dep.scopt,
Dep.pureconfig,
Expand All @@ -207,9 +213,8 @@ def testDep(project: Project): ClasspathDependency = project % "compile->compile

val Hugo = config("hugo")
lazy val hugo = Module("hugo", "riddl-hugo")
.configure(With.typical)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.configure(With.coverage(65))
.configure(With.publishing)
.configure(With.MiMa("0.52.1"))
.settings(
coverageExcludedFiles := """<empty>;$anon""",
Expand All @@ -223,10 +228,9 @@ lazy val hugo = Module("hugo", "riddl-hugo")

val Commands = config("commands")
lazy val commands: Project = Module("commands", "riddl-commands")
.configure(With.typical)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.configure(With.coverage(50))
.configure(With.MiMa("0.52.1"))
.configure(With.publishing)
.settings(
coverageExcludedFiles := """<empty>;$anon""",
scalacOptions ++= Seq("-explain", "--explain-types", "--explain-cyclic"),
Expand All @@ -245,7 +249,7 @@ lazy val commands: Project = Module("commands", "riddl-commands")

val Riddlc = config("riddlc")
lazy val riddlc: Project = Program("riddlc", "riddlc")
.configure(With.typical)
.configure(With.typical, With.publishing, With.headerLicense("Apache-2.0"))
.configure(With.coverage(50.0))
.configure(With.publishing)
.configure(With.noMiMa)
Expand Down Expand Up @@ -306,6 +310,7 @@ lazy val docsite = DocSite(

lazy val plugin = Plugin("sbt-riddl")
.configure(With.build_info, With.scala2, With.noMiMa, With.publishing)
.configure(With.headerLicense("Apache-2.0"))
.settings(
description := "An sbt plugin to embellish a project with riddlc usage",
buildInfoObject := "SbtRiddlPluginBuildInfo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.command

import com.ossuminc.riddl.language.Messages.{Messages, errors}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.command

import com.ossuminc.riddl.command.CommandOptions.optional
Expand Down Expand Up @@ -67,7 +68,7 @@ object CommonOptionsHelper {
.optional()
.action((_, c) => c.copy(quiet = true))
.text("Do not print out any output, just do the requested command"),
opt[Unit]('a', "noANSIMessages")
opt[Unit]('a', "no-ansi-messages")
.optional()
.action((_, c) => c.copy(noANSIMessages = true))
.text("Do not print messages with ANSI formatting"),
Expand Down Expand Up @@ -184,7 +185,7 @@ object CommonOptionsHelper {
val (common, effects1) = OParser.runParser[CommonOptions](
commonOptionsParser,
options,
com.ossuminc.riddl.utils.CommonOptions.empty,
com.ossuminc.riddl.utils.CommonOptions.default,
setup
)
OParser.runEffects(effects1, dontTerminate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.command

import com.ossuminc.riddl.language.Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.command

import com.ossuminc.riddl.language.AST.*
Expand Down
25 changes: 15 additions & 10 deletions commands/src/main/scala/com/ossuminc/riddl/commands/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.language.{At, Messages}
Expand Down Expand Up @@ -52,7 +53,7 @@ object Commands:
end loadCommandNamed

/** Probably the easiest way to run a command if you're familiar with the command line options and still get the
* [[Messages.Messages]] or [[com.ossuminc.riddl.passes.PassesResult]] objects out of it.
* [[com.ossuminc.riddl.language.Messages.Messages]] or [[com.ossuminc.riddl.passes.PassesResult]] objects out of it.
*
* @param args
* An [[Array[String]] of arguments, one argument per array element. This should follow the same pattern as by the
Expand All @@ -62,8 +63,7 @@ object Commands:
* @return
* One of two things:
* - [[scala.util.Left]] of [[com.ossuminc.riddl.language.Messages.Messages]] if the command fails and the
* contained [[com.ossuminc.riddl.language.Messages.Messages]], a [[scala.collection.immutable.List]] of
* [[com.ossuminc.riddl.language.Messages.Message]], that explain why it failed
* contained messages, a [[List]] of [[com.ossuminc.riddl.language.Messages.Messages]], that explain the errors
* - [[scala.util.Right]] of [[com.ossuminc.riddl.passes.PassesResult]] to provide the details of what the
* [[com.ossuminc.riddl.passes.Pass]]es that run produced.
*/
Expand All @@ -72,8 +72,9 @@ object Commands:
)(using io: PlatformContext): Either[Messages, PassesResult] =
require(args.nonEmpty, "Empty argument list provided")
val name = args.head
val result = loadCommandNamed(name)
.flatMap { cmd => cmd.run(args) }
val result = loadCommandNamed(name).flatMap { cmd =>
cmd.run(args)
}
if io.options.verbose then
val rc = if result.isRight then "yes" else "no"
io.log.info(s"Ran: ${args.mkString(" ")}: success=$rc")
Expand Down Expand Up @@ -197,9 +198,10 @@ object Commands:
val (common, remaining) = CommonOptionsHelper.parseCommonOptions(args)
common match
case Some(commonOptions) =>
io.setOptions(commonOptions)
if remaining.isEmpty then Left(List(error("No command argument was provided")))
else runCommandWithArgs(remaining)
io.withOptions(commonOptions) { _ =>
if remaining.isEmpty then Left(List(error("No command argument was provided")))
else runCommandWithArgs(remaining)
}
case None =>
Left(List(error("Option parsing failed, terminating.")))
end match
Expand All @@ -210,16 +212,19 @@ object Commands:

def runMain(args: Array[String])(using io: PlatformContext): Int =
try

val (common, remaining) = CommonOptionsHelper.parseCommonOptions(args)
common match
case Some(commonOptions) =>
io.setOptions(commonOptions)
handleCommandRun(remaining)
io.withOptions[Int](commonOptions) { _ =>
handleCommandRun(remaining)
}
case None =>
// arguments are bad, error message will have been displayed
io.log.info("Option parsing failed, terminating.")
1
end match

catch
case NonFatal(exception) =>
io.log.severe("Exception Thrown:", exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Ossum, Inc.
* Copyright 2019 Ossum, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.commands.Commands
import com.ossuminc.riddl.language.Messages.Messages
import com.ossuminc.riddl.passes.PassesResult
import com.ossuminc.riddl.utils.{CommonOptions, PlatformContext, Logger, StringHelpers}
import com.ossuminc.riddl.utils.{pc,ec}
import com.ossuminc.riddl.utils.{CommonOptions, PlatformContext, StringHelpers}

import pureconfig.ConfigCursor
import pureconfig.ConfigReader
Expand Down Expand Up @@ -82,20 +80,17 @@ class FromCommand(using io: PlatformContext) extends Command[FromCommand.Options
s"Failed to read common options from ${options.inputFile.get} because:\n" ++
messages.format
)
CommonOptions.empty
end if
io.options

end match
io.setOptions(loadedCO)
// configFile: Option[Path],
// targetCommand: String,
// commonOptions: CommonOptions,
// log: Logger,
// commandName: String
val result = Commands.runFromConfig(
options.inputFile,
options.targetCommand,
"from"
)
result
io.withOptions(loadedCO) { _ =>
Commands.runFromConfig(
options.inputFile,
options.targetCommand,
"from"
)
}
}

override def replaceInputFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.command.{Command, CommandOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.command.CommandOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

/** Unit Tests For Running Riddlc Commands from Plugins */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2019 Ossum, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.command.{Command, CommandOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.command.{Command, CommandOptions, CommonOptionsHelper}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2019 Ossum, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Ossum, Inc.
* Copyright 2019 Ossum, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.utils.SysLogger
import com.ossuminc.riddl.utils.pc

import java.nio.file.{Path,Files}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2019 Ossum, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.commands.{CommandTestBase,InputFileCommand}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

package com.ossuminc.riddl.commands

import com.ossuminc.riddl.utils.{PlatformContext, JVMPlatformContext}
import com.ossuminc.riddl.utils.{AbstractTestingBasis, PlatformContext}
import org.scalatest.*
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec

/** A base class for specs that just want to run a command */
abstract class RunCommandSpecBase extends AnyWordSpec with Matchers {
abstract class RunCommandSpecBase(using io: PlatformContext) extends AbstractTestingBasis {

given io: PlatformContext = JVMPlatformContext()
def runWith(
commandArgs: Seq[String]
): Assertion = { Commands.runMain(commandArgs.toArray) must be(0) }
Expand Down
Loading

0 comments on commit ca43c02

Please sign in to comment.