diff --git a/build.gradle.kts b/build.gradle.kts index 59ae807..5313a86 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -106,7 +106,7 @@ dependencies { exclude(group = "org.codehaus.groovy") } functionalTestImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") - functionalTestImplementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.6") + functionalTestImplementation("com.github.ajalt.clikt:clikt:4.2.1") } publishing { diff --git a/src/functionalTest/kotlin/io/github/platan/tests_execution_chart/JsonToHtmlReportApp.kt b/src/functionalTest/kotlin/io/github/platan/tests_execution_chart/JsonToHtmlReportApp.kt index 2014414..e4c108e 100644 --- a/src/functionalTest/kotlin/io/github/platan/tests_execution_chart/JsonToHtmlReportApp.kt +++ b/src/functionalTest/kotlin/io/github/platan/tests_execution_chart/JsonToHtmlReportApp.kt @@ -2,15 +2,17 @@ package io.github.platan.tests_execution_chart +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.parameters.options.default +import com.github.ajalt.clikt.parameters.options.option +import com.github.ajalt.clikt.parameters.options.required +import com.github.ajalt.clikt.parameters.types.boolean +import com.github.ajalt.clikt.parameters.types.int import io.github.platan.tests_execution_chart.report.ReportConfig import io.github.platan.tests_execution_chart.report.ReportCreator import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport import io.github.platan.tests_execution_chart.reporters.Logger import io.github.platan.tests_execution_chart.reporters.html.HtmlConfig -import kotlinx.cli.ArgParser -import kotlinx.cli.ArgType -import kotlinx.cli.default -import kotlinx.cli.required import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream @@ -25,35 +27,38 @@ private val logger = object : Logger { } } +private class CommandLineParser : CliktCommand() { + val input by option(envvar = "input", help = "Input file in JSON format").required() + val outputDir by option(envvar = "output-dir").required() + val mermaidScriptSrc by option(envvar = "mermaid-script-src").default(HtmlConfig.Script.getSrcDefault()) + val embed by option(envvar = "embed-mermaid-script").boolean().default(false) + val maxTextSize by option(envvar = "mermaid-max-text-size").int().default(50_000) + val taskName by option(envvar = "task-name").default("test") + + override fun run() = Unit +} + @OptIn(ExperimentalSerializationApi::class) fun main(args: Array) { - val parser = ArgParser("jsonToHtml") - val input by parser.option(ArgType.String, fullName = "input", description = "Input file in JSON format").required() - val outputDir by parser.option(ArgType.String, fullName = "output-dir").required() - val mermaidScriptSrc by parser.option(ArgType.String, fullName = "mermaid-script-src") - .default(HtmlConfig.Script.getSrcDefault()) - val embed by parser.option(ArgType.Boolean, fullName = "embed-mermaid-script").default(false) - val maxTextSize by parser.option(ArgType.Int, fullName = "mermaid-max-text-size").default(50_000) - val taskName by parser.option(ArgType.String, fullName = "task-name").default("test") - - parser.parse(args) + val commandLineParser = CommandLineParser() + commandLineParser.main(args) val outputLocation = "html-report" - val report = json.decodeFromStream(FileInputStream(input)) + val report = json.decodeFromStream(FileInputStream(commandLineParser.input)) val reportConfig = ReportConfig( listOf( HtmlConfig( true, outputLocation, HtmlConfig.Script( - mermaidScriptSrc, - embed, - HtmlConfig.Script.Options(maxTextSize) + commandLineParser.mermaidScriptSrc, + commandLineParser.embed, + HtmlConfig.Script.Options(commandLineParser.maxTextSize) ) ), ), ReportConfig.Marks(), false, ) - ReportCreator(logger).createReports(report, reportConfig, File(outputDir), taskName) + ReportCreator(logger).createReports(report, reportConfig, File(commandLineParser.outputDir), commandLineParser.taskName) }