Skip to content

Commit

Permalink
[skip-ci] WIP #2
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Nov 16, 2022
1 parent 67932de commit e2dd4b2
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions diktat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<artifactId>diktat-rules</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-cli-jvm</artifactId>
</dependency>

<dependency>
<groupId>org.cqfn.diktat</groupId>
Expand Down
53 changes: 53 additions & 0 deletions diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt
Original file line number Diff line number Diff line change
@@ -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<String>) {
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<DiktatReporterType>(),
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<DiktatLogLevel>(),
fullName = "log-level",
shortName = "l",
description = "Enable the output of specified level",
).default(DiktatLogLevel.INFO)
val logLevel: DiktatLogLevel by logLevelOption

parser.parse(args)

}
7 changes: 7 additions & 0 deletions diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cqfn.diktat.api

enum class DiktatLogLevel {
DEBUG,
INFO,
TRACE,
}
23 changes: 23 additions & 0 deletions diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -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,
)
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.code.style>official</kotlin.code.style>
<kotlinx.serialization.version>1.4.1</kotlinx.serialization.version>
<kotlinx-cli.version>0.3.5</kotlinx-cli.version>
<ktlint.version>0.47.1</ktlint.version>
<junit.version>5.9.1</junit.version>
<junit.platform.version>1.9.1</junit.platform.version>
Expand Down Expand Up @@ -132,6 +133,16 @@
<artifactId>kotlinx-serialization-json-jvm</artifactId>
<version>${kotlinx.serialization.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-cli</artifactId>
<version>${kotlinx-cli.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-cli-jvm</artifactId>
<version>${kotlinx-cli.version}</version>
</dependency>
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-core</artifactId>
Expand Down

0 comments on commit e2dd4b2

Please sign in to comment.