Skip to content

Commit

Permalink
deps: Update clikt to version 5.0.0 and Mordant to version 3.0.0
Browse files Browse the repository at this point in the history
These updates need to be done together, also see [1]. Adjust code for
various API changes and deprecations / upcoming removal of properties.

[1]: ajalt/mordant#230

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
renovate[bot] authored and sschuberth committed Sep 16, 2024
1 parent 5a303ad commit a488e05
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 38 deletions.
19 changes: 8 additions & 11 deletions cli/src/main/kotlin/OrtMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import ch.qos.logback.classic.Logger

import com.github.ajalt.clikt.completion.completionOption
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.core.main
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.output.MordantHelpFormatter
import com.github.ajalt.clikt.parameters.options.associate
Expand All @@ -44,8 +46,6 @@ import com.github.ajalt.mordant.table.grid

import kotlin.system.exitProcess

import org.apache.logging.log4j.kotlin.logger

import org.ossreviewtoolkit.model.config.LicenseFilePatterns
import org.ossreviewtoolkit.model.config.OrtConfiguration
import org.ossreviewtoolkit.plugins.commands.api.OrtCommand
Expand Down Expand Up @@ -86,11 +86,7 @@ fun main(args: Array<String>) {
exitProcess(0)
}

class OrtMain : CliktCommand(
name = ORT_NAME,
epilog = "$REQUIRED_OPTION_MARKER denotes required options.",
invokeWithoutSubcommand = true
) {
class OrtMain : CliktCommand(ORT_NAME) {
private val configFile by option("--config", "-c", help = "The path to a configuration file.")
.convert { it.expandTilde() }
.file(mustExist = true, canBeFile = true, canBeDir = false, mustBeWritable = false, mustBeReadable = true)
Expand Down Expand Up @@ -122,7 +118,6 @@ class OrtMain : CliktCommand(
completionOption()

context {
expandArgumentFiles = false
helpFormatter = { MordantHelpFormatter(context = it, REQUIRED_OPTION_MARKER, showDefaultValues = true) }
}

Expand All @@ -136,6 +131,10 @@ class OrtMain : CliktCommand(
)
}

override val invokeWithoutSubcommand = true

override fun helpEpilog(context: Context) = "$REQUIRED_OPTION_MARKER denotes required options."

override fun run() {
// This is somewhat dirty: For logging, ORT uses the Log4j API (because of its nice Kotlin API), but Logback as
// the implementation (for its robustness). The former API does not provide a way to set the root log level,
Expand All @@ -145,8 +144,6 @@ class OrtMain : CliktCommand(
val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger
rootLogger.level = logLevel

logger.debug { "Used command line arguments: ${currentContext.originalArgv}" }

// Make the parameter globally available.
printStackTrace = stacktrace

Expand Down Expand Up @@ -176,7 +173,7 @@ class OrtMain : CliktCommand(
private fun getOrtHeader(version: String): Widget =
grid {
column(0) {
width = ColumnWidth.Custom(width = null, expandWeight = null, priority = HIGHEST_PRIORITY_FOR_WIDTH)
width = ColumnWidth(width = null, expandWeight = null, priority = HIGHEST_PRIORITY_FOR_WIDTH)
}

column(1) { verticalAlign = VerticalAlign.BOTTOM }
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ versionsPlugin = "0.51.0"

asciidoctorj = "3.0.0"
asciidoctorjPdf = "2.3.18"
clikt = "4.4.0"
clikt = "5.0.0"
commonsCompress = "1.27.1"
cvssCalculator = "1.4.3"
cyclonedx = "9.0.5"
Expand Down Expand Up @@ -48,7 +48,7 @@ logback = "1.5.8"
maven = "3.9.9"
mavenResolver = "1.9.22"
mockk = "1.13.12"
mordant = "2.7.2"
mordant = "3.0.0"
okhttp = "4.12.0"
postgres = "42.7.4"
postgresEmbedded = "1.1.0"
Expand Down
10 changes: 5 additions & 5 deletions helper-cli/src/main/kotlin/HelperMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ 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.context
import com.github.ajalt.clikt.core.main
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.output.MordantHelpFormatter
import com.github.ajalt.clikt.parameters.options.default
Expand Down Expand Up @@ -57,10 +59,7 @@ fun main(args: Array<String>) {

private const val REQUIRED_OPTION_MARKER = "*"

internal class HelperMain : CliktCommand(
name = ORTH_NAME,
epilog = "$REQUIRED_OPTION_MARKER denotes required options."
) {
internal class HelperMain : CliktCommand(ORTH_NAME) {
private val logLevel by option(help = "Set the verbosity level of log output.").switch(
"--error" to Level.ERROR,
"--warn" to Level.WARN,
Expand All @@ -72,7 +71,6 @@ internal class HelperMain : CliktCommand(

init {
context {
expandArgumentFiles = false
helpFormatter = { MordantHelpFormatter(context = it, REQUIRED_OPTION_MARKER, showDefaultValues = true) }
}

Expand Down Expand Up @@ -107,6 +105,8 @@ internal class HelperMain : CliktCommand(
)
}

override fun helpEpilog(context: Context) = "$REQUIRED_OPTION_MARKER denotes required options."

override fun run() {
// This is somewhat dirty: For logging, ORT uses the Log4j API (because of its nice Kotlin API), but Logback as
// the implementation (for its robustness). The former API does not provide a way to set the root log level,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@

package org.ossreviewtoolkit.helper.commands.classifications

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands

import org.ossreviewtoolkit.model.licenses.LicenseClassifications

internal class LicenseClassificationsCommand : NoOpCliktCommand(
help = "Commands for working with license classifications."
) {
internal class LicenseClassificationsCommand : NoOpCliktCommand() {
init {
subcommands(
FilterCommand(),
ImportCommand(),
MergeCommand()
)
}

override fun help(context: Context) = "Commands for working with license classifications."
}

internal fun LicenseClassifications.prefixCategoryNames(prefix: String) =
Expand Down
7 changes: 4 additions & 3 deletions helper-cli/src/main/kotlin/commands/dev/DevCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

package org.ossreviewtoolkit.helper.commands.dev

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands

internal class DevCommand : NoOpCliktCommand(
help = "Commands for development."
) {
internal class DevCommand : NoOpCliktCommand() {
init {
subcommands(
RewriteTestAssetsCommand()
)
}

override fun help(context: Context) = "Commands for development."
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

package org.ossreviewtoolkit.helper.commands.packageconfig

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands

internal class PackageConfigurationCommand : NoOpCliktCommand(
help = "Commands for working with package configurations."
) {
internal class PackageConfigurationCommand : NoOpCliktCommand() {
init {
subcommands(
CreateCommand(),
Expand All @@ -38,4 +37,6 @@ internal class PackageConfigurationCommand : NoOpCliktCommand(
RemoveEntriesCommand()
)
}

override fun help(context: Context) = "Commands for working with package configurations."
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@

package org.ossreviewtoolkit.helper.commands.packagecuration

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands

internal class PackageCurationsCommand : NoOpCliktCommand(
help = "Commands for working with package curations."
) {
internal class PackageCurationsCommand : NoOpCliktCommand() {
init {
subcommands(
CreateCommand(),
SetCommand(),
SplitCommand()
)
}

override fun help(context: Context) = "Commands for working with package curations."
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

package org.ossreviewtoolkit.helper.commands.provenancestorage

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands

internal class ProvenanceStorageCommand : NoOpCliktCommand(
help = "Commands for working with provenance storages."
) {
internal class ProvenanceStorageCommand : NoOpCliktCommand() {
init {
subcommands(
DeleteCommand()
)
}

override fun help(context: Context) = "Commands for working with provenance storages."
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

package org.ossreviewtoolkit.helper.commands.repoconfig

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands

internal class RepositoryConfigurationCommand : NoOpCliktCommand(
help = "Commands for working with package configurations."
) {
internal class RepositoryConfigurationCommand : NoOpCliktCommand() {
init {
subcommands(
ExportLicenseFindingCurationsCommand(),
Expand All @@ -39,4 +38,6 @@ internal class RepositoryConfigurationCommand : NoOpCliktCommand(
SortCommand()
)
}

override fun help(context: Context) = "Commands for working with package configurations."
}
5 changes: 4 additions & 1 deletion helper-cli/src/main/kotlin/utils/OrtHelperCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
package org.ossreviewtoolkit.helper.utils

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context

internal abstract class OrtHelperCommand(name: String? = null, help: String) : CliktCommand(name = name, help = help)
internal abstract class OrtHelperCommand(name: String? = null, private val help: String) : CliktCommand(name) {
override fun help(context: Context) = help
}
5 changes: 4 additions & 1 deletion plugins/commands/api/src/main/kotlin/OrtCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.ossreviewtoolkit.plugins.commands.api

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.UsageError
import com.github.ajalt.clikt.core.requireObject

Expand All @@ -32,7 +33,7 @@ import org.ossreviewtoolkit.utils.ort.ORT_CONFIG_FILENAME
/**
* An interface for [CliktCommand]-based ORT commands that come as named plugins.
*/
abstract class OrtCommand(name: String, help: String) : CliktCommand(name = name, help = help), Plugin {
abstract class OrtCommand(name: String, private val help: String) : CliktCommand(name), Plugin {
companion object {
/**
* All [ORT commands][OrtCommand] available in the classpath, associated by their names.
Expand All @@ -42,6 +43,8 @@ abstract class OrtCommand(name: String, help: String) : CliktCommand(name = name

override val type = commandName

override fun help(context: Context) = help

protected val ortConfig by requireObject<OrtConfiguration>()

/**
Expand Down

0 comments on commit a488e05

Please sign in to comment.