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

application.CentralContractRepoReportCommand.kt Maven / Gradle / Ivy

There is a newer version: 2.0.37
Show newest version
package application

import io.specmatic.core.log.logger
import io.specmatic.core.utilities.saveJsonFile
import io.specmatic.reports.CentralContractRepoReport
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import picocli.CommandLine
import java.util.concurrent.Callable

@CommandLine.Command(
    name = "central-contract-repo-report",
    mixinStandardHelpOptions = true,
    description = ["Generate the Central Contract Repo Report"]
)
class CentralContractRepoReportCommand : Callable {

    companion object {
        const val REPORT_PATH = "./build/reports/specmatic"
        const val REPORT_FILE_NAME = "central_contract_repo_report.json"
    }

    @CommandLine.Option(names = ["--baseDir"], description = ["Directory to treated as the root for API specifications"], defaultValue = "")
    lateinit var baseDir: String

    override fun call() {
        val report = CentralContractRepoReport().generate(baseDir)
        if(report.specifications.isEmpty()) {
            logger.log("No specifications found, hence the Central Contract Repo Report has not been generated.")
        }
        else {
            logger.log("Saving Central Contract Repo Report json to $REPORT_PATH ...")
            val json = Json {
                encodeDefaults = false
            }
            val reportJson = json.encodeToString(report)
            saveJsonFile(reportJson, REPORT_PATH, REPORT_FILE_NAME)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy