From 7253ec34656c76f37a25bdcb171f6e63f08f3a06 Mon Sep 17 00:00:00 2001 From: "bartosz.kolej" Date: Wed, 18 Oct 2023 14:54:12 +0200 Subject: [PATCH 1/2] Migrate kotlinx-cli to clikt --- build.gradle.kts | 2 +- .../JsonToHtmlReportApp.kt | 43 +++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) 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..10ba8fc 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 reportBuilder = CommandLineParser() + reportBuilder.main(args) val outputLocation = "html-report" - val report = json.decodeFromStream(FileInputStream(input)) + val report = json.decodeFromStream(FileInputStream(reportBuilder.input)) val reportConfig = ReportConfig( listOf( HtmlConfig( true, outputLocation, HtmlConfig.Script( - mermaidScriptSrc, - embed, - HtmlConfig.Script.Options(maxTextSize) + reportBuilder.mermaidScriptSrc, + reportBuilder.embed, + HtmlConfig.Script.Options(reportBuilder.maxTextSize) ) ), ), ReportConfig.Marks(), false, ) - ReportCreator(logger).createReports(report, reportConfig, File(outputDir), taskName) + ReportCreator(logger).createReports(report, reportConfig, File(reportBuilder.outputDir), reportBuilder.taskName) } From 73bfcdba4a5d13344c8c33ca2b33dd13c0d3713d Mon Sep 17 00:00:00 2001 From: "bartosz.kolej" Date: Wed, 18 Oct 2023 15:09:15 +0200 Subject: [PATCH 2/2] change variable name --- .../tests_execution_chart/JsonToHtmlReportApp.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 10ba8fc..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 @@ -40,25 +40,25 @@ private class CommandLineParser : CliktCommand() { @OptIn(ExperimentalSerializationApi::class) fun main(args: Array) { - val reportBuilder = CommandLineParser() - reportBuilder.main(args) + val commandLineParser = CommandLineParser() + commandLineParser.main(args) val outputLocation = "html-report" - val report = json.decodeFromStream(FileInputStream(reportBuilder.input)) + val report = json.decodeFromStream(FileInputStream(commandLineParser.input)) val reportConfig = ReportConfig( listOf( HtmlConfig( true, outputLocation, HtmlConfig.Script( - reportBuilder.mermaidScriptSrc, - reportBuilder.embed, - HtmlConfig.Script.Options(reportBuilder.maxTextSize) + commandLineParser.mermaidScriptSrc, + commandLineParser.embed, + HtmlConfig.Script.Options(commandLineParser.maxTextSize) ) ), ), ReportConfig.Marks(), false, ) - ReportCreator(logger).createReports(report, reportConfig, File(reportBuilder.outputDir), reportBuilder.taskName) + ReportCreator(logger).createReports(report, reportConfig, File(commandLineParser.outputDir), commandLineParser.taskName) }