Skip to content

Commit

Permalink
Merge 6bab708 into d73ead2
Browse files Browse the repository at this point in the history
  • Loading branch information
reid-spencer committed Sep 29, 2023
2 parents d73ead2 + 6bab708 commit ba274f7
Show file tree
Hide file tree
Showing 109 changed files with 5,707 additions and 5,287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ object CommandOptions {
}
}

@SuppressWarnings(Array("org.wartremover.warts.IterableOps"))
val commandOptionsParser: OParser[Unit, CommandOptions] = {
val plugins = Plugin.loadPluginsFrom[CommandPlugin[CommandOptions]]()
val list =
for plugin <- plugins yield { plugin.pluginName -> plugin.getOptions }
val parsers = list.sortBy(_._1).map(_._2._1) // alphabetize
OParser.sequence(parsers.head, parsers.tail*)
require(parsers.nonEmpty, "No command line options parsers!")
OParser.sequence(parsers.head, parsers.drop(1)*)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,20 @@ object CommandPlugin {
remaining: Array[String],
commonOptions: CommonOptions
): Int = {
var log: Logger = SysLogger()
val log: Logger =
if commonOptions.quiet then
StringLogger()
else
SysLogger()

if remaining.isEmpty then {
if !commonOptions.quiet then {
log.error("No command argument was provided")
}
log.error("No command argument was provided")
1
} else {
val name = remaining.head
if commonOptions.dryRun then {
if !commonOptions.quiet then {
log.info(s"Would have executed: ${remaining.mkString(" ")}")
}
}
if commonOptions.quiet then { log = StringLogger() }
if commonOptions.dryRun then
log.info(s"Would have executed: ${remaining.mkString(" ")}")

val result = CommandPlugin
.runCommandWithArgs(name, remaining, log, commonOptions)
handleCommandResult(result, commonOptions, log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class FromCommand extends CommandPlugin[FromCommand.Options](FromCommand.cmdName
outputDirOverride: Option[Path]
): Either[Messages, PassesResult] = {
val loadedCO =
CommandOptions.loadCommonOptions(options.inputFile.get) match {
CommandOptions.loadCommonOptions(options.inputFile.fold(Path.of(""))(identity)) match {
case Right(newCO: CommonOptions) =>
if commonOptions.verbose then {
println(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ abstract class PassCommand[OPT <: PassCommandOptions : ClassTag](name: String) e
outputDirOverride: Option[Path]
): Either[Messages, PassesResult] = {
val options =
if outputDirOverride.nonEmpty then {
overrideOptions(originalOptions, outputDirOverride.get)
} else {originalOptions}
if outputDirOverride.nonEmpty then
val path = outputDirOverride.fold(Path.of(""))(identity)
overrideOptions(originalOptions, path)
else
originalOptions

val messages = checkOptions(options)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class RepeatCommand
* @return
* Either a set of Messages on error or a Unit on success
*/
@SuppressWarnings(Array("org.wartremover.warts.Var"))
override def run(
options: Options,
commonOptions: CommonOptions,
Expand Down
170 changes: 92 additions & 78 deletions hugo/src/main/scala/com/reactific/riddl/hugo/HugoCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ object HugoCommand {
siteLogoPath: Option[String] = Some("images/logo.png"),
siteLogoURL: Option[URL] = None,
baseUrl: Option[URL] = Option(java.net.URI.create("https://example.com/").toURL),
themes: Seq[(String, Option[URL])] =
Seq("hugo-geekdoc" -> Option(HugoPass.geekDoc_url)),
themes: Seq[(String, Option[URL])] = Seq("hugo-geekdoc" -> Option(HugoPass.geekDoc_url)),
sourceURL: Option[URL] = None,
editPath: Option[String] = Some("edit/main/src/main/riddl"),
viewPath: Option[String] = Some("blob/main/src/main/riddl"),
withGlossary: Boolean = true,
withTODOList: Boolean = true,
withGraphicalTOC: Boolean = false,
withStatistics: Boolean = true)
extends CommandOptions with TranslatingOptions {
withStatistics: Boolean = true
) extends CommandOptions
with TranslatingOptions {
def command: String = "hugo"

def outputRoot: Path = outputDir.getOrElse(Path.of("")).toAbsolutePath
Expand All @@ -65,62 +65,73 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {

override def getOptions: (OParser[Unit, Options], Options) = {
import builder.*
cmd("hugo").text(
"""Parse and validate the input-file and then translate it into the input
|needed for hugo to translate it to a functioning web site."""
.stripMargin
).children(
inputFile((v, c) => c.copy(inputFile = Option(v.toPath))),
outputDir((v, c) => c.copy(outputDir = Option(v.toPath))),
opt[String]('p', "project-name").optional()
.action((v, c) => c.copy(projectName = Option(v)))
.text("optional project name to associate with the generated output")
.validate(n =>
if n.isBlank then {
Left("option project-name cannot be blank or empty")
} else { Right(()) }
),
opt[String]('E', "enterprise-name").optional()
.action((v, c) => c.copy(projectName = Option(v)))
.text("optional enterprise name for C4 diagram output").validate(n =>
if n.isBlank then {
Left("option enterprise-name cannot be blank or empty")
} else { Right(()) }
),
opt[Boolean]('e', name = "erase-output")
.text("Erase entire output directory before putting out files")
.optional().action((v, c) => c.copy(eraseOutput = v)),
opt[Boolean]('e', name = "with-statistics")
.text("Generate a statistics page accessible from index page")
.optional().action((v, c) => c.copy(withStatistics = v)),
opt[Boolean]('e', name = "with-glossary")
.text("Generate a glossary of terms and definitions ").optional()
.action((v, c) => c.copy(withGlossary = v)),
opt[Boolean]('e', name = "with-todo-list").text("Generate a To Do list")
.optional().action((v, c) => c.copy(withTODOList = v)),
opt[Boolean]('e', name = "with-graphical-toc")
.text("Generate a graphically navigable table of contents").optional()
.action((v, c) => c.copy(withGraphicalTOC = v)),
opt[URL]('b', "base-url").optional()
.action((v, c) => c.copy(baseUrl = Some(v)))
.text("Optional base URL for root of generated http URLs"),
opt[Map[String, String]]('t', name = "themes").action((t, c) =>
c.copy(themes = t.toSeq.map(x => x._1 -> Some(java.net.URI.create(x._2).toURL)))
).text("Add theme name/url pairs to use alternative Hugo themes"),
opt[URL]('s', name = "source-url")
.action((u, c) => c.copy(baseUrl = Option(u)))
.text("URL to the input file's Git Repository"),
opt[String]('h', name = "edit-path")
.action((h, c) => c.copy(editPath = Option(h)))
.text("Path to add to source-url to allow editing"),
opt[String]('m', "site-logo-path")
.action((s, c) => c.copy(siteLogoPath = Option(s)))
.text("""Path, in 'static' directory to placement and use
cmd("hugo")
.text(
"""Parse and validate the input-file and then translate it into the input
|needed for hugo to translate it to a functioning web site.""".stripMargin
)
.children(
inputFile((v, c) => c.copy(inputFile = Option(v.toPath))),
outputDir((v, c) => c.copy(outputDir = Option(v.toPath))),
opt[String]('p', "project-name")
.optional()
.action((v, c) => c.copy(projectName = Option(v)))
.text("optional project name to associate with the generated output")
.validate(n =>
if n.isBlank then {
Left("option project-name cannot be blank or empty")
} else { Right(()) }
),
opt[String]('E', "enterprise-name")
.optional()
.action((v, c) => c.copy(projectName = Option(v)))
.text("optional enterprise name for C4 diagram output")
.validate(n =>
if n.isBlank then {
Left("option enterprise-name cannot be blank or empty")
} else { Right(()) }
),
opt[Boolean]('e', name = "erase-output")
.text("Erase entire output directory before putting out files")
.optional()
.action((v, c) => c.copy(eraseOutput = v)),
opt[Boolean]('e', name = "with-statistics")
.text("Generate a statistics page accessible from index page")
.optional()
.action((v, c) => c.copy(withStatistics = v)),
opt[Boolean]('e', name = "with-glossary")
.text("Generate a glossary of terms and definitions ")
.optional()
.action((v, c) => c.copy(withGlossary = v)),
opt[Boolean]('e', name = "with-todo-list")
.text("Generate a To Do list")
.optional()
.action((v, c) => c.copy(withTODOList = v)),
opt[Boolean]('e', name = "with-graphical-toc")
.text("Generate a graphically navigable table of contents")
.optional()
.action((v, c) => c.copy(withGraphicalTOC = v)),
opt[URL]('b', "base-url")
.optional()
.action((v, c) => c.copy(baseUrl = Some(v)))
.text("Optional base URL for root of generated http URLs"),
opt[Map[String, String]]('t', name = "themes")
.action((t, c) => c.copy(themes = t.toSeq.map(x => x._1 -> Some(java.net.URI.create(x._2).toURL))))
.text("Add theme name/url pairs to use alternative Hugo themes"),
opt[URL]('s', name = "source-url")
.action((u, c) => c.copy(baseUrl = Option(u)))
.text("URL to the input file's Git Repository"),
opt[String]('h', name = "edit-path")
.action((h, c) => c.copy(editPath = Option(h)))
.text("Path to add to source-url to allow editing"),
opt[String]('m', "site-logo-path")
.action((s, c) => c.copy(siteLogoPath = Option(s)))
.text("""Path, in 'static' directory to placement and use
|of the site logo.""".stripMargin),
opt[String]('n', "site-logo-url")
.action((s, c) => c.copy(siteLogoURL = Option(java.net.URI(s).toURL)))
.text("URL from which to copy the site logo.")
) -> HugoCommand.Options()
opt[String]('n', "site-logo-url")
.action((s, c) => c.copy(siteLogoURL = Option(java.net.URI(s).toURL)))
.text("URL from which to copy the site logo.")
) -> HugoCommand.Options()
}

override def getConfigReader: ConfigReader[Options] = { (cur: ConfigCursor) =>
Expand All @@ -135,8 +146,8 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {
eraseOutput <- optional(objCur, "erase-output", true) { cc =>
cc.asBoolean
}
projectName <- optional(objCur, "project-name", "No Project Name") {
cur => cur.asString
projectName <- optional(objCur, "project-name", "No Project Name") { cur =>
cur.asString
}
enterpriseName <-
optional(objCur, "enterprise-name", "No Enterprise Name") { cur =>
Expand All @@ -149,26 +160,26 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {
optional(objCur, "site-description", "No Site Description") { cur =>
cur.asString
}
siteLogoPath <- optional(objCur, "site-logo-path", "static/somewhere") {
cc => cc.asString
siteLogoPath <- optional(objCur, "site-logo-path", "static/somewhere") { cc =>
cc.asString
}
siteLogoURL <- optional(objCur, "site-logo-url", Option.empty[String]) {
cc => cc.asString.map(Option[String])
siteLogoURL <- optional(objCur, "site-logo-url", Option.empty[String]) { cc =>
cc.asString.map(Option[String])
}
baseURL <- optional(objCur, "base-url", Option.empty[String]) { cc =>
cc.asString.map(Option[String])
}
themesMap <- optional(objCur, "themes", Map.empty[String, ConfigCursor]) {
cc => cc.asMap
themesMap <- optional(objCur, "themes", Map.empty[String, ConfigCursor]) { cc =>
cc.asMap
}
sourceURL <- optional(objCur, "source-url", Option.empty[String]) { cc =>
cc.asString.map(Option[String])
}
viewPath <- optional(objCur, "view-path", "blob/main/src/main/riddl") {
cc => cc.asString
viewPath <- optional(objCur, "view-path", "blob/main/src/main/riddl") { cc =>
cc.asString
}
editPath <- optional(objCur, "edit-path", "edit/main/src/main/riddl") {
cc => cc.asString
editPath <- optional(objCur, "edit-path", "edit/main/src/main/riddl") { cc =>
cc.asString
}
withGlossary <- optional(objCur, "with-glossary", true) { cc =>
cc.asBoolean
Expand All @@ -183,12 +194,14 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {
cc.asBoolean
}
yield {
def handleURL(url: Option[String]): Option[URL] = {
if url.isEmpty || url.get.isEmpty then None
else Option(java.net.URI(url.get).toURL)
}
def handleURL(url: Option[String]): Option[URL] =
url match {
case None => Option.empty[URL]
case Some(u) if u.isEmpty => Option.empty[URL]
case Some(u) => Option(java.net.URI(u).toURL)
}

val themes =
val themes: Seq[(String, Option[java.net.URL])] = {
if themesMap.isEmpty then {
Seq("hugo-geekdoc" -> Option(HugoPass.geekDoc_url))
} else {
Expand All @@ -199,11 +212,13 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {
case Right(s) => handleURL(Option(s))
case Left(x) =>
val errs = x.prettyPrint(1)
throw new IllegalArgumentException(errs)
require(false, errs)
None
}
}
}
}
}
HugoCommand.Options(
Option(Path.of(inputPath)),
Option(Path.of(outputPath)),
Expand Down Expand Up @@ -231,7 +246,6 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {
options.copy(outputDir = Some(newOutputDir))
}


def getPasses(
log: Logger,
commonOptions: CommonOptions,
Expand Down
Loading

0 comments on commit ba274f7

Please sign in to comment.