Skip to content

Commit fa763c8

Browse files
committed
chore: update to latest clikt
Signed-off-by: Sam Gammon <sam@elide.dev>
1 parent 0149dd6 commit fa763c8

File tree

11 files changed

+39
-18
lines changed

11 files changed

+39
-18
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ abiCheck = "0.17.0"
33
antlr = "4.+"
44
assertj = "3.+"
55
checksumPlugin = "1.4.0"
6-
clikt = "3.+"
6+
clikt = "5.+"
77
commonMark = "0.+"
88
downloadTaskPlugin = "5.6.0"
99
geantyref = "1.+"

pkl-cli/src/main/kotlin/org/pkl/cli/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.pkl.cli
1919

20+
import com.github.ajalt.clikt.core.main
2021
import com.github.ajalt.clikt.core.subcommands
2122
import org.pkl.cli.commands.*
2223
import org.pkl.commons.cli.cliMain

pkl-cli/src/main/kotlin/org/pkl/cli/commands/AnalyzeCommand.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.pkl.cli.commands
1717

18+
import com.github.ajalt.clikt.core.Context
1819
import com.github.ajalt.clikt.core.NoOpCliktCommand
1920
import com.github.ajalt.clikt.core.subcommands
2021
import com.github.ajalt.clikt.parameters.options.option
@@ -25,16 +26,17 @@ import org.pkl.cli.CliImportAnalyzerOptions
2526
import org.pkl.commons.cli.commands.ModulesCommand
2627
import org.pkl.commons.cli.commands.single
2728

28-
class AnalyzeCommand(helpLink: String) :
29+
class AnalyzeCommand(private val helpLink: String) :
2930
NoOpCliktCommand(
3031
name = "analyze",
31-
help = "Commands related to static analysis",
32-
epilog = "For more information, visit $helpLink"
3332
) {
3433
init {
3534
subcommands(AnalyzeImportsCommand(helpLink))
3635
}
3736

37+
override fun help(context: Context): String = "Commands related to static analysis"
38+
override fun helpEpilog(context: Context): String = "For more information, visit $helpLink"
39+
3840
companion object {
3941
class AnalyzeImportsCommand(helpLink: String) :
4042
ModulesCommand(

pkl-cli/src/main/kotlin/org/pkl/cli/commands/ProjectCommand.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.pkl.cli.commands
1717

18+
import com.github.ajalt.clikt.core.Context
1819
import com.github.ajalt.clikt.core.NoOpCliktCommand
1920
import com.github.ajalt.clikt.core.subcommands
2021
import com.github.ajalt.clikt.parameters.arguments.argument
@@ -31,16 +32,17 @@ import org.pkl.commons.cli.commands.BaseCommand
3132
import org.pkl.commons.cli.commands.TestOptions
3233
import org.pkl.commons.cli.commands.single
3334

34-
class ProjectCommand(helpLink: String) :
35+
class ProjectCommand(private val helpLink: String) :
3536
NoOpCliktCommand(
3637
name = "project",
37-
help = "Run commands related to projects",
38-
epilog = "For more information, visit $helpLink"
3938
) {
4039
init {
4140
subcommands(ResolveCommand(helpLink), PackageCommand(helpLink))
4241
}
4342

43+
override fun help(context: Context): String = "Run commands related to projects"
44+
override fun helpEpilog(context: Context): String = "For more information, visit $helpLink"
45+
4446
companion object {
4547
class ResolveCommand(helpLink: String) :
4648
BaseCommand(

pkl-cli/src/main/kotlin/org/pkl/cli/commands/RootCommand.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,27 @@
1515
*/
1616
package org.pkl.cli.commands
1717

18+
import com.github.ajalt.clikt.core.Context
1819
import com.github.ajalt.clikt.core.NoOpCliktCommand
1920
import com.github.ajalt.clikt.core.context
2021
import com.github.ajalt.clikt.parameters.options.versionOption
2122

22-
class RootCommand(name: String, version: String, helpLink: String) :
23+
class RootCommand(name: String, version: String, private val helpLink: String) :
2324
NoOpCliktCommand(
2425
name = name,
25-
printHelpOnEmptyArgs = true,
26-
epilog = "For more information, visit $helpLink",
2726
) {
2827
init {
2928
versionOption(version, names = setOf("-v", "--version"), message = { it })
3029

3130
context {
32-
correctionSuggestor = { given, possible ->
31+
suggestTypoCorrection = { given, possible ->
3332
if (!given.startsWith("-")) {
3433
registeredSubcommands().map { it.commandName }
3534
} else possible
3635
}
3736
}
3837
}
38+
39+
override fun helpEpilog(context: Context): String = "For more information, visit $helpLink"
40+
override val printHelpOnEmptyArgs: Boolean get() = true
3941
}

pkl-cli/src/main/kotlin/org/pkl/cli/commands/ServerCommand.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
package org.pkl.cli.commands
1717

1818
import com.github.ajalt.clikt.core.CliktCommand
19+
import com.github.ajalt.clikt.core.Context
1920
import org.pkl.cli.CliServer
2021
import org.pkl.commons.cli.CliBaseOptions
2122

22-
class ServerCommand(helpLink: String) :
23+
class ServerCommand(private val helpLink: String) :
2324
CliktCommand(
2425
name = "server",
25-
help = "Run as a server that communicates over standard input/output",
26-
epilog = "For more information, visit $helpLink"
2726
) {
2827

28+
override fun help(context: Context): String =
29+
"Run as a server that communicates over standard input/output"
30+
31+
override fun helpEpilog(context: Context): String =
32+
"For more information, visit $helpLink"
33+
2934
override fun run() {
3035
CliServer(CliBaseOptions()).run()
3136
}

pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.pkl.codegen.java
1919

20+
import com.github.ajalt.clikt.core.main
2021
import com.github.ajalt.clikt.parameters.options.*
2122
import com.github.ajalt.clikt.parameters.types.path
2223
import java.nio.file.Path

pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.pkl.codegen.kotlin
1919

20+
import com.github.ajalt.clikt.core.main
2021
import com.github.ajalt.clikt.parameters.options.associate
2122
import com.github.ajalt.clikt.parameters.options.default
2223
import com.github.ajalt.clikt.parameters.options.flag

pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseCommand.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
package org.pkl.commons.cli.commands
1717

1818
import com.github.ajalt.clikt.core.CliktCommand
19+
import com.github.ajalt.clikt.core.Context
1920
import com.github.ajalt.clikt.parameters.groups.provideDelegate
2021

21-
abstract class BaseCommand(name: String, helpLink: String, help: String = "") :
22-
CliktCommand(name = name, help = help, epilog = "For more information, visit $helpLink") {
22+
abstract class BaseCommand(name: String, private val helpLink: String, help: String = "") :
23+
CliktCommand(name = name) {
24+
private val helpText = help
25+
26+
override fun help(context: Context): String = helpText
27+
override fun helpEpilog(context: Context): String = "For more information, visit $helpLink"
28+
2329
val baseOptions: BaseOptions by BaseOptions()
2430
}

pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/OptionExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.splitAll(
4343
transformEach = { it },
4444
transformAll = { it.flatten().ifEmpty { default } },
4545
validator = {},
46-
nvalues = 1,
47-
valueSplit = Regex.fromLiteral(separator)
46+
nvalues = 1..1,
47+
valueSplit = { Regex.fromLiteral(separator).split(it) },
4848
)
4949
}

0 commit comments

Comments
 (0)