From 65978a1d553585c4197881d1913ff817680fc84f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:05:14 +0200 Subject: [PATCH] fix(deps): update dependency com.github.ajalt.clikt:clikt to v5 (#2798) * fix(deps): update dependency com.github.ajalt.clikt:clikt to v5 * Upgrade com.github.ajalt.clikt:clikt to v5 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Paul Dingemans --- gradle/libs.versions.toml | 2 +- .../main/kotlin/com/pinterest/ktlint/Main.kt | 1 + .../GenerateEditorConfigSubCommand.kt | 10 ++-- .../cli/internal/GitHookCliktCommand.kt | 7 ++- .../internal/GitPreCommitHookSubCommand.kt | 2 +- .../cli/internal/GitPrePushHookSubCommand.kt | 2 +- .../ktlint/cli/internal/KtlintCommandLine.kt | 56 +++++++++---------- 7 files changed, 42 insertions(+), 38 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 08fd374aed..4369085c41 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ kotlinx-binary-compatibiltiy-validator = "org.jetbrains.kotlinx.binary-compatibi kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" } kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-plugin-dev = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinDev" } -clikt = "com.github.ajalt.clikt:clikt:4.4.0" +clikt = "com.github.ajalt.clikt:clikt:5.0.0" dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20" ec4j = "org.ec4j.core:ec4j-core:0.3.0" logging = "io.github.oshai:kotlin-logging-jvm:7.0.0" diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/Main.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/Main.kt index d830098358..a1e5fda1e9 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/Main.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/Main.kt @@ -2,6 +2,7 @@ package com.pinterest.ktlint +import com.github.ajalt.clikt.core.main import com.github.ajalt.clikt.core.subcommands import com.pinterest.ktlint.cli.internal.GenerateEditorConfigSubCommand import com.pinterest.ktlint.cli.internal.GitPreCommitHookSubCommand diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GenerateEditorConfigSubCommand.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GenerateEditorConfigSubCommand.kt index f06a0ec7e1..7f99d7e665 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GenerateEditorConfigSubCommand.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GenerateEditorConfigSubCommand.kt @@ -1,6 +1,7 @@ package com.pinterest.ktlint.cli.internal import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required import com.github.ajalt.clikt.parameters.types.enum @@ -14,11 +15,10 @@ import java.nio.file.Paths private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() -internal class GenerateEditorConfigSubCommand : - CliktCommand( - name = "generateEditorConfig", - help = "Generate kotlin style section for '.editorconfig' file. Output should be copied manually to the '.editorconfig' file.", - ) { +internal class GenerateEditorConfigSubCommand : CliktCommand(name = "generateEditorConfig") { + override fun help(context: Context) = + "Generate kotlin style section for '.editorconfig' file. Output should be copied manually to the '.editorconfig' file." + // No default value is set as users should explicitly choose one of the code styles. In this way, it is more clear that the generated // content is determined by the chosen value. If a default (ktlint_official) is set, and the user has not specified the code style, the // user might not be aware that the value of the other properties are dependent on the code style. diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitHookCliktCommand.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitHookCliktCommand.kt index daca2ce560..200ff25fb0 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitHookCliktCommand.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitHookCliktCommand.kt @@ -1,6 +1,7 @@ package com.pinterest.ktlint.cli.internal import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context import java.io.File import java.io.IOException import java.math.BigInteger @@ -11,8 +12,10 @@ private const val DEFAULT_GIT_HOOKS_DIR = "hooks" internal abstract class GitHookCliktCommand( name: String, - help: String, -) : CliktCommand(name = name, help = help) { + val helpText: String, +) : CliktCommand(name = name) { + override fun help(context: Context) = helpText + fun installGitHook( gitHookName: String, hookContentProvider: () -> ByteArray, diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPreCommitHookSubCommand.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPreCommitHookSubCommand.kt index cd537d6899..3380171b9e 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPreCommitHookSubCommand.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPreCommitHookSubCommand.kt @@ -3,7 +3,7 @@ package com.pinterest.ktlint.cli.internal internal class GitPreCommitHookSubCommand : GitHookCliktCommand( name = "installGitPreCommitHook", - help = "Install git hook to automatically check files for style violations on commit", + helpText = "Install git hook to automatically check files for style violations on commit", ) { override fun run() { installGitHook(gitHookName = "pre-commit") { diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPrePushHookSubCommand.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPrePushHookSubCommand.kt index 54d068c49a..0660bfc941 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPrePushHookSubCommand.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/GitPrePushHookSubCommand.kt @@ -3,7 +3,7 @@ package com.pinterest.ktlint.cli.internal internal class GitPrePushHookSubCommand : GitHookCliktCommand( name = "installGitPrePushHook", - help = "Install git hook to automatically check files for style violations before push", + helpText = "Install git hook to automatically check files for style violations before push", ) { override fun run() { installGitHook(gitHookName = "pre-push") { diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt index 41c5fa2a7b..4235076011 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt @@ -3,6 +3,7 @@ package com.pinterest.ktlint.cli.internal import ch.qos.logback.classic.Level import ch.qos.logback.classic.Logger import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context import com.github.ajalt.clikt.core.MutuallyExclusiveGroupException import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.multiple @@ -67,51 +68,50 @@ import kotlin.system.exitProcess private lateinit var logger: KLogger -internal class KtlintCommandLine : - CliktCommand( - name = "ktlint", - invokeWithoutSubcommand = true, - help = - """ - An anti-bikeshedding Kotlin linter with built-in formatter. - (https://pinterest.github.io/ktlint/latest/). +internal class KtlintCommandLine : CliktCommand(name = "ktlint") { + override fun help(context: Context) = + """ + An anti-bikeshedding Kotlin linter with built-in formatter. + (https://pinterest.github.io/ktlint/latest/). - Usage on Windows: - java -jar ktlint.jar [] []... []... + Usage on Windows: + java -jar ktlint.jar [] []... []... - # EXAMPLES + # EXAMPLES - ## Use default patterns + ## Use default patterns - Check the style of all Kotlin files (ending with '.kt' or '.kts') inside the current dir (recursively). Hidden folders will be skipped. + Check the style of all Kotlin files (ending with '.kt' or '.kts') inside the current dir (recursively). Hidden folders will be skipped. - `ktlint` + `ktlint` - ## Specify patterns + ## Specify patterns - Check only certain locations starting from the current directory. Prepend ! to negate the pattern, KtLint uses .gitignore pattern style syntax. Globs are applied starting from the last one. + Check only certain locations starting from the current directory. Prepend ! to negate the pattern, KtLint uses .gitignore pattern style syntax. Globs are applied starting from the last one. - Check all '.kt' files in 'src/' directory, but ignore files ending with 'Test.kt': + Check all '.kt' files in 'src/' directory, but ignore files ending with 'Test.kt': - `ktlint "src/**/*.kt" "!src/**/*Test.kt"` + `ktlint "src/**/*.kt" "!src/**/*Test.kt"` - Check all '.kt' files in 'src/' directory, but ignore 'generated' directory and its subdirectories: + Check all '.kt' files in 'src/' directory, but ignore 'generated' directory and its subdirectories: - `ktlint "src/**/*.kt" "!src/**/generated/**"` + `ktlint "src/**/*.kt" "!src/**/generated/**"` - ## Auto-correct style violations + ## Auto-correct style violations - Check all '.kt' files in 'src/' directory, and when possible automatically correct the lint violations: + Check all '.kt' files in 'src/' directory, and when possible automatically correct the lint violations: - `ktlint -F "src/**/*.kt"` + `ktlint -F "src/**/*.kt"` - ## Using custom reporter jar and overriding report location + ## Using custom reporter jar and overriding report location - `ktlint --reporter=csv,artifact=/path/to/reporter/csv.jar,output=my-custom-report.csv` + `ktlint --reporter=csv,artifact=/path/to/reporter/csv.jar,output=my-custom-report.csv` + + # Options and commands + """.trimIndent() + + override val invokeWithoutSubcommand = true - # Options and commands - """.trimIndent(), - ) { init { versionOption(KtlintVersionProvider().version, names = setOf("-v", "--version")) }