Skip to content

Commit

Permalink
Update Kotlin to 1.4 (#228)
Browse files Browse the repository at this point in the history
I didn't enable the [hierarchical MPP structure](https://kotlinlang.org/docs/reference/mpp-share-on-platforms.html#share-code-on-similar-platforms) because it breaks the build due to `platform.posix` libraries not being supported in shared source sets.
  • Loading branch information
ajalt committed Aug 20, 2020
1 parent e89296c commit 92d844c
Show file tree
Hide file tree
Showing 47 changed files with 55 additions and 135 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
- Multiple short lines in a help text paragraph no longer appear dedented ([#215](https://github.com/ajalt/clikt/issues/215))

### Changed
- Updated Kotlin to 1.4.0
- `Argument.help` and `Option.help` properties have been renamed to `argumentHelp` and `optionHelp`, respectively. The `help` parameter names to `option()` and `argument()` are unchanged.
- `commandHelp` and `commandHelpEpilog` properties on `CliktCommand` are now `open`, so you can choose to override them instead of passing `help` and `epilog` to the constructor.
- Replaced `MapValueSource.defaultKey` with `ValueSource.getKey()`, which is more customizable.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -3,7 +3,7 @@ import java.io.ByteArrayOutputStream
val VERSION_NAME: String by project

plugins {
kotlin("jvm").version("1.3.72")
kotlin("jvm").version("1.4.0")
id("org.jetbrains.dokka").version("0.10.1")
}

Expand Down
76 changes: 42 additions & 34 deletions clikt/build.gradle.kts
Expand Up @@ -12,62 +12,70 @@ plugins {
}


// True if intellij is running. When true, we create a single native target named "native" using the
// current OS. Otherwise (when run with gradle), we create all native targets and have them depend
// on the native module. If we don't do this, IntelliJ won't know what target the nativeMain source
// set is for, and won't resolve references to native libraries.
val ideaActive = System.getProperty("idea.active") == "true"
val os = org.gradle.internal.os.OperatingSystem.current()!!

kotlin {
jvm()
js { nodejs() }
js {
nodejs()
browser()
}

linuxX64()
mingwX64()
macosX64()

if (ideaActive) {
if (os.isMacOsX) macosX64("native")
if (os.isWindows) mingwX64("native")
if (os.isLinux) linuxX64("native")
}

sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}

get("commonMain").dependencies {
api(kotlin("stdlib-common"))
}
val commonMain by getting {}

get("commonTest").dependencies {
api(kotlin("test-common"))
api(kotlin("test-annotations-common"))
api("io.kotest:kotest-assertions-core:4.1.0")
val commonTest by getting {
dependencies {
api(kotlin("test-common"))
api(kotlin("test-annotations-common"))
api("io.kotest:kotest-assertions-core:4.2.0")
}
}

get("jvmMain").dependencies {
api(kotlin("stdlib"))
val jvmTest by getting {
dependencies {
api(kotlin("test-junit"))
api("com.github.stefanbirkner:system-rules:1.18.0")
api("com.google.jimfs:jimfs:1.1")
}
}

get("jvmTest").dependencies {
api(kotlin("test-junit"))
val jsTest by getting {
dependencies {
api(kotlin("test-js"))
}
}

get("jsMain").dependencies {
api(kotlin("stdlib-js"))
val nativeMain by creating {
dependsOn(commonMain)
}

get("jsTest").dependencies {
api(kotlin("test-js"))
val linuxX64Main by getting {
dependsOn(nativeMain)
}
val mingwX64Main by getting {
dependsOn(nativeMain)
}
val macosX64Main by getting {
dependsOn(nativeMain)
}

val nativeMain = if (ideaActive) get("nativeMain") else create("nativeMain")

listOf("macosX64Main", "linuxX64Main", "mingwX64Main").forEach {
get(it).dependsOn(nativeMain)
val nativeTest by creating {
dependsOn(commonTest)
}
val linuxX64Test by getting {
dependsOn(nativeTest)
}
val mingwX64Test by getting {
dependsOn(nativeTest)
}
val macosX64Test by getting {
dependsOn(nativeTest)
}
}
}
Expand Down
Expand Up @@ -15,7 +15,7 @@ internal object CompletionGenerator {
.flatMap { arg -> (1..arg.nvalues).map { "'${arg.name}'" } }
.joinToString(" ")
val varargName = command._arguments.find { it.nvalues < 0 }?.name.orEmpty()
val paramsWithCandidates = (options.map { o -> o.first.maxBy { it.length }!! to o.second } + arguments)
val paramsWithCandidates = (options.map { o -> o.first.maxByOrNull { it.length }!! to o.second } + arguments)

if (options.isEmpty() && subcommands.isEmpty() && arguments.isEmpty()) return ""

Expand Down Expand Up @@ -92,7 +92,7 @@ internal object CompletionGenerator {
append(" __skip_opt_eq\n")
if (nargs > 0) {
append(" (( i = i + $nargs ))\n")
append(" [[ \${i} -gt COMP_CWORD ]] && in_param='${names.maxBy { it.length }}' || in_param=''\n")
append(" [[ \${i} -gt COMP_CWORD ]] && in_param='${names.maxByOrNull { it.length }}' || in_param=''\n")
} else {
append(" in_param=''\n")
}
Expand Down
Expand Up @@ -5,7 +5,6 @@ import com.github.ajalt.clikt.output.CliktHelpFormatter
import com.github.ajalt.clikt.output.HelpFormatter
import com.github.ajalt.clikt.output.defaultCliktConsole
import com.github.ajalt.clikt.sources.ChainedValueSource
import com.github.ajalt.clikt.sources.ExperimentalValueSourceApi
import com.github.ajalt.clikt.sources.ValueSource
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
Expand Down
Expand Up @@ -218,7 +218,7 @@ open class CliktHelpFormatter(
}

private fun measureFirstColumn(rows: List<DefinitionRow>): Int =
rows.maxBy { it.col1.graphemeLength }?.col1?.graphemeLength?.coerceAtMost(maxColWidth) ?: maxColWidth
rows.maxByOrNull { it.col1.graphemeLength }?.col1?.graphemeLength?.coerceAtMost(maxColWidth) ?: maxColWidth

private fun StringBuilder.section(title: String) {
append("\n").append(renderSectionTitle(title)).append("\n")
Expand Down
Expand Up @@ -103,7 +103,7 @@ internal fun inferOptionNames(names: Set<String>, propertyName: String): Set<Str
internal fun inferEnvvar(names: Set<String>, envvar: String?, autoEnvvarPrefix: String?): String? {
if (envvar != null) return envvar
if (names.isEmpty() || autoEnvvarPrefix == null) return null
val name = splitOptionPrefix(names.maxBy { it.length }!!).second
val name = splitOptionPrefix(names.maxByOrNull { it.length }!!).second
if (name.isEmpty()) return null
return autoEnvvarPrefix + "_" + name.replace(Regex("\\W"), "_").toUpperCase()
}
Expand Down Expand Up @@ -136,7 +136,7 @@ internal fun <EachT, AllT> deprecationTransformer(
transformAll(it)
}

internal fun Option.longestName(): String? = names.maxBy { it.length }
internal fun Option.longestName(): String? = names.maxByOrNull { it.length }

internal sealed class FinalValue {
data class Parsed(val values: List<OptionParser.Invocation>) : FinalValue()
Expand Down
Expand Up @@ -3,9 +3,9 @@ package com.github.ajalt.clikt.core
import com.github.ajalt.clikt.testing.TestCommand
import com.github.ajalt.clikt.testing.parse
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.beInstanceOf
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.beInstanceOf
import io.kotest.matchers.types.shouldBeSameInstanceAs
import kotlin.js.JsName
import kotlin.test.Test
Expand Down Expand Up @@ -77,7 +77,7 @@ class ContextTest {
shouldThrow<NullPointerException> { parent.o2 }
shouldThrow<NullPointerException> { child.o2 }

parent.o1 should beInstanceOf<Foo>()
parent.o1 should beInstanceOf(Foo::class)
parent.o2 shouldBeSameInstanceAs parent.o1
child.o1 shouldBeSameInstanceAs parent.o1
child.o2 shouldBeSameInstanceAs parent.o1
Expand Down
Expand Up @@ -2,7 +2,6 @@ package com.github.ajalt.clikt.testing

import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.options.Option
import com.github.ajalt.clikt.sources.ExperimentalValueSourceApi
import com.github.ajalt.clikt.sources.MapValueSource
import com.github.ajalt.clikt.sources.ValueSource
import io.kotest.matchers.shouldBe
Expand Down
@@ -1,8 +1,8 @@
package com.github.ajalt.clikt.output

import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.mpp.readEnvvar
import com.github.ajalt.clikt.mpp.nodeRequire
import com.github.ajalt.clikt.mpp.readEnvvar

internal actual fun createEditor(
editorPath: String?,
Expand Down
@@ -1,7 +1,6 @@
package com.github.ajalt.clikt.parameters.types

import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.output.TermUi
import com.github.ajalt.clikt.parameters.arguments.ProcessedArgument
import com.github.ajalt.clikt.parameters.arguments.RawArgument
import com.github.ajalt.clikt.parameters.arguments.convert
Expand Down
@@ -1,7 +1,6 @@
package com.github.ajalt.clikt.parameters.types

import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.output.TermUi
import com.github.ajalt.clikt.parameters.arguments.ProcessedArgument
import com.github.ajalt.clikt.parameters.arguments.RawArgument
import com.github.ajalt.clikt.parameters.arguments.convert
Expand Down
Expand Up @@ -5,7 +5,6 @@ import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.clikt.parameters.types.int
import com.github.ajalt.clikt.sources.ExperimentalValueSourceApi
import com.github.ajalt.clikt.testing.TestCommand
import com.github.ajalt.clikt.testing.TestSource
import com.github.ajalt.clikt.testing.parse
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions gradlew
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
3 changes: 0 additions & 3 deletions settings.gradle.kts
@@ -1,7 +1,4 @@
enableFeaturePreview("GRADLE_METADATA")

include("clikt")
include("test")
include("samples:copy")
include("samples:repo")
include("samples:validation")
Expand Down
59 changes: 0 additions & 59 deletions test/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 92d844c

Please sign in to comment.