All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.reactific.riddl.stats.StatsCommand.scala Maven / Gradle / Ivy

Go to download

RIDDL is a language and toolset for specifying a system design using ideas from DDD, reactive architecture, distributed systems patterns, and other software architecture practices.

There is a newer version: 0.27.5
Show newest version
/*
 * Copyright 2019 Ossum, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package com.reactific.riddl.stats

import com.reactific.riddl.commands.InputFileCommandPlugin
import com.reactific.riddl.language.Messages.Messages
import com.reactific.riddl.language.CommonOptions
import com.reactific.riddl.passes.{Pass, PassesResult, Riddl}
import com.reactific.riddl.utils.Logger

import java.nio.file.Path

/** Validate Command */
class StatsCommand extends InputFileCommandPlugin("stats") {
  import InputFileCommandPlugin.Options

  override def run(
    options: Options,
    commonOptions: CommonOptions,
    log: Logger,
    outputDirOverride: Option[Path]
  ): Either[Messages, PassesResult] = {
    options.withInputFile { (inputFile: Path) =>
      val passes = Pass.standardPasses ++ Seq({ (input, output) => StatsPass(input, output) })
      Riddl.parseAndValidatePath(inputFile, commonOptions, passes = passes, logger = log) match {
        case Left(messages) => Left(messages)
        case Right(result) =>
          result.outputOf[StatsOutput](StatsPass.name) match {
            case Some(stats) =>
              println(s"Maximum Depth: ${stats.maximum_depth}")
              for (k, v) <- stats.categories do {
                println(s"$k: $v")
              }
              println()
            case None => println("No statistics generated")
          }
          Right(result)
      }
    }
  }

  override def replaceInputFile(
    opts: Options,
    inputFile: Path
  ): Options = { opts.copy(inputFile = Some(inputFile)) }

  override def loadOptionsFrom(
    configFile: Path,
    commonOptions: CommonOptions
  ): Either[Messages, Options] = {
    super.loadOptionsFrom(configFile, commonOptions).map { options =>
      resolveInputFileToConfigFile(options, commonOptions, configFile)
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy