Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace kotlinx cli #77

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}