From e2dd4b22d1c74f946573a5e030b477e3bfe38048 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 16 Nov 2022 13:14:32 +0300 Subject: [PATCH] [skip-ci] WIP #2 --- diktat/pom.xml | 4 ++ .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 53 +++++++++++++++++++ .../org/cqfn/diktat/api/DiktatLogLevel.kt | 7 +++ .../org/cqfn/diktat/api/DiktatReporterType.kt | 23 ++++++++ .../org/cqfn/diktat/cli/DiktatProperties.kt | 3 ++ pom.xml | 11 ++++ 6 files changed, 101 insertions(+) create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt diff --git a/diktat/pom.xml b/diktat/pom.xml index 66af555f35..1893b9cdec 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -18,6 +18,10 @@ diktat-rules ${project.version} + + org.jetbrains.kotlinx + kotlinx-cli-jvm + org.cqfn.diktat diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index c53fdd5111..305caa4eb5 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -1,5 +1,58 @@ package org.cqfn.diktat +import org.cqfn.diktat.api.DiktatLogLevel +import org.cqfn.diktat.api.DiktatReporterType +import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF +import kotlinx.cli.ArgParser +import kotlinx.cli.ArgType +import kotlinx.cli.default + fun main(args: Array) { + val parser = ArgParser("diktat") + val configOption = parser.option( + type = ArgType.String, + fullName = "config", + shortName = "c", + description = """ + Specify the location of the YAML configuration file. + By default, $DIKTAT_ANALYSIS_CONF in the current + directory is used. + """.trimIndent(), + ).default(DIKTAT_ANALYSIS_CONF) + val config: String by configOption + + val formatOption = parser.option( + type = ArgType.Boolean, + fullName = "format", + shortName = "F", + description = "Fix any deviations from the code style." + ).default(false) + val format: Boolean by formatOption + + val reporterOption = parser.option( + type = ArgType.Choice(), + fullName = "reporter", + shortName = "r", + description = "The reporter to use", + ).default(DiktatReporterType.PLAIN) + val reporter: DiktatReporterType by reporterOption + + val outputOption = parser.option( + type = ArgType.String, + fullName = "output", + shortName = "o", + description = "Redirect the reporter output to a file.", + ) + val output: String? by outputOption + + val logLevelOption = parser.option( + type = ArgType.Choice(), + fullName = "log-level", + shortName = "l", + description = "Enable the output of specified level", + ).default(DiktatLogLevel.INFO) + val logLevel: DiktatLogLevel by logLevelOption + + parser.parse(args) } diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt new file mode 100644 index 0000000000..a383b93201 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt @@ -0,0 +1,7 @@ +package org.cqfn.diktat.api + +enum class DiktatLogLevel { + DEBUG, + INFO, + TRACE, +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt new file mode 100644 index 0000000000..a39516b0a8 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt @@ -0,0 +1,23 @@ +package org.cqfn.diktat.api + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Type of reporting in `diktat` + */ +@Serializable +enum class DiktatReporterType { + @SerialName("plain") + PLAIN, + @SerialName("plain_group_by_file") + PLAIN_GROUP_BY_FILE, + @SerialName("json") + JSON, + @SerialName("sarif") + SARIF, + @SerialName("checkstyle") + CHECKSTYLE, + @SerialName("html") + HTML, +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 11341cccf9..74d74f08ad 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -1,7 +1,10 @@ package org.cqfn.diktat.cli +import org.cqfn.diktat.api.DiktatLogLevel + data class DiktatProperties( val config: String, val reporter: String, val output: String, + val logLevel: DiktatLogLevel, ) diff --git a/pom.xml b/pom.xml index 1d24f62f83..1613a411e4 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ true official 1.4.1 + 0.3.5 0.47.1 5.9.1 1.9.1 @@ -132,6 +133,16 @@ kotlinx-serialization-json-jvm ${kotlinx.serialization.version} + + org.jetbrains.kotlinx + kotlinx-cli + ${kotlinx-cli.version} + + + org.jetbrains.kotlinx + kotlinx-cli-jvm + ${kotlinx-cli.version} + com.pinterest.ktlint ktlint-core