io.gitlab.arturbosch.detekt.cli.CliRunner.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of detekt-cli Show documentation
Show all versions of detekt-cli Show documentation
Static code analysis for Kotlin
package io.gitlab.arturbosch.detekt.cli
import io.github.detekt.tooling.api.AnalysisResult
import io.github.detekt.tooling.api.DetektCli
import io.github.detekt.tooling.api.UnexpectedError
import io.github.detekt.tooling.internal.DefaultAnalysisResult
import io.github.detekt.tooling.internal.EmptyContainer
import io.gitlab.arturbosch.detekt.cli.runners.ConfigExporter
import io.gitlab.arturbosch.detekt.cli.runners.Runner
import io.gitlab.arturbosch.detekt.cli.runners.VersionPrinter
class CliRunner : DetektCli {
override fun run(args: Array): AnalysisResult = run(args, System.out, System.err)
override fun run(args: Array, outputChannel: Appendable, errorChannel: Appendable): AnalysisResult {
val arguments = runCatching { parseArguments(args) }
.getOrElse { return DefaultAnalysisResult(null, UnexpectedError(it)) }
val specialRunner = when {
arguments.showVersion -> VersionPrinter(outputChannel)
arguments.generateConfig -> ConfigExporter(arguments, outputChannel)
else -> null
}
return if (specialRunner != null) {
runCatching { specialRunner.execute() }
.map { DefaultAnalysisResult(EmptyContainer) }
.getOrElse { DefaultAnalysisResult(null, UnexpectedError(it)) }
} else {
Runner(arguments, outputChannel, errorChannel).call()
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy