Skip to content

Commit d2f7a18

Browse files
authored
Add CoreNoOpCliktCommand (#531)
#526 Made the `NoOpCliktCommand` available in `core`, and this PR follows up by renaming it to match the other core commands and making a separate command that uses mordant. While it is a bit annoying to need separate copies of all the commands just to install mordant, I don't know of a better solution that works an all multiplatform targets.
1 parent cf0f0f1 commit d2f7a18

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

clikt-mordant/api/clikt-mordant.api

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public final class com/github/ajalt/clikt/core/MordantContextKt {
4343
public static final fun setTerminal (Lcom/github/ajalt/clikt/core/Context$Builder;Lcom/github/ajalt/mordant/terminal/Terminal;)V
4444
}
4545

46+
public class com/github/ajalt/clikt/core/NoOpCliktCommand : com/github/ajalt/clikt/core/CliktCommand {
47+
public fun <init> ()V
48+
public fun <init> (Ljava/lang/String;)V
49+
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
50+
public final fun run ()V
51+
}
52+
4653
public class com/github/ajalt/clikt/output/MordantHelpFormatter : com/github/ajalt/clikt/output/AbstractHelpFormatter {
4754
public fun <init> (Lcom/github/ajalt/clikt/core/Context;Ljava/lang/String;ZZ)V
4855
public synthetic fun <init> (Lcom/github/ajalt/clikt/core/Context;Ljava/lang/String;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.ajalt.clikt.core
2+
3+
/**
4+
* A [CoreCliktCommand] that has a default implementation of [CliktCommand.run] that is a no-op.
5+
*/
6+
open class NoOpCliktCommand(
7+
/**
8+
* The name of the program to use in the help output. If not given, it is inferred from the
9+
* class name.
10+
*/
11+
name: String? = null,
12+
) : CliktCommand(name) {
13+
final override fun run() {}
14+
}

clikt-mordant/src/commonTest/kotlin/com/github/ajalt/clikt/core/CliktCommandTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CliktCommandTest {
3434
class ListAllValuesCommand : TestCommand()
3535
class LGTMMeansLookingGoodToMe : TestCommand()
3636
class `nothing-to-change` : TestCommand()
37-
class ListCommands : NoOpCliktCommand()
37+
class ListCommands : CoreNoOpCliktCommand()
3838
ListAllValuesCommand().commandName shouldBe "list-all-values"
3939
LGTMMeansLookingGoodToMe().commandName shouldBe "lgtmmeans-looking-good-to-me"
4040
`nothing-to-change`().commandName shouldBe "nothing-to-change"

clikt/api/clikt.api

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ public final class com/github/ajalt/clikt/core/CoreCliktCommandKt {
307307
public static final fun parse (Lcom/github/ajalt/clikt/core/CoreCliktCommand;[Ljava/lang/String;)V
308308
}
309309

310+
public class com/github/ajalt/clikt/core/CoreNoOpCliktCommand : com/github/ajalt/clikt/core/CoreCliktCommand {
311+
public fun <init> ()V
312+
public fun <init> (Ljava/lang/String;)V
313+
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
314+
public final fun run ()V
315+
}
316+
310317
public final class com/github/ajalt/clikt/core/FileNotFound : com/github/ajalt/clikt/core/UsageError {
311318
public fun <init> (Ljava/lang/String;)V
312319
public fun formatMessage (Lcom/github/ajalt/clikt/output/Localization;Lcom/github/ajalt/clikt/output/ParameterFormatter;)Ljava/lang/String;
@@ -374,13 +381,6 @@ public final class com/github/ajalt/clikt/core/MutuallyExclusiveGroupException :
374381
public final fun getNames ()Ljava/util/List;
375382
}
376383

377-
public class com/github/ajalt/clikt/core/NoOpCliktCommand : com/github/ajalt/clikt/core/CoreCliktCommand {
378-
public fun <init> ()V
379-
public fun <init> (Ljava/lang/String;)V
380-
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
381-
public final fun run ()V
382-
}
383-
384384
public final class com/github/ajalt/clikt/core/NoSuchArgument : com/github/ajalt/clikt/core/UsageError {
385385
public fun <init> (Ljava/util/List;)V
386386
public fun formatMessage (Lcom/github/ajalt/clikt/output/Localization;Lcom/github/ajalt/clikt/output/ParameterFormatter;)Ljava/lang/String;

clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/NoOpCliktCommand.kt renamed to clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/CoreNoOpCliktCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.github.ajalt.clikt.core
33
/**
44
* A [CoreCliktCommand] that has a default implementation of [CoreCliktCommand.run] that is a no-op.
55
*/
6-
open class NoOpCliktCommand(
6+
open class CoreNoOpCliktCommand(
77
/**
88
* The name of the program to use in the help output. If not given, it is inferred from the
99
* class name.

samples/aliases/src/main/kotlin/com/github/ajalt/clikt/samples/aliases/main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.io.File
1010
* @param configFile A config file containing aliases, one per line, in the form `token = alias`. Aliases can
1111
* have multiple tokens (e.g. `cm = commit -m`).
1212
*/
13-
class AliasedCli(private val configFile: File) : NoOpCliktCommand() {
13+
class AliasedCli(private val configFile: File) : CoreNoOpCliktCommand() {
1414
override fun help(context: Context) = "An example that supports aliased subcommands"
1515
override fun aliases(): Map<String, List<String>> {
1616
return configFile.readLines().map { it.split("=", limit = 2) }

0 commit comments

Comments
 (0)