Skip to content

Commit

Permalink
Merge pull request #77 from KKolej/replace-kotlinx-cli
Browse files Browse the repository at this point in the history
Replace kotlinx cli
  • Loading branch information
platan authored Oct 18, 2023
2 parents d3470e0 + 73bfcdb commit cb0c657
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String>) {
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<TestExecutionScheduleReport>(FileInputStream(input))
val report = json.decodeFromStream<TestExecutionScheduleReport>(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)
}

0 comments on commit cb0c657

Please sign in to comment.