Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit 5ca9f67

Browse files
authored
Add Gradle test fixtures migrator CLI (#181)
* Add Gradle test fixtures migrator CLI * detekt issues * Add a playground * update API * Spotless
1 parent 9bf9a2e commit 5ca9f67

File tree

4 files changed

+541
-0
lines changed

4 files changed

+541
-0
lines changed

api/kotlin-cli-util.api

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public final class slack/cli/CliUtilKt {
2525
public static synthetic fun filterByName$default (Lkotlin/sequences/Sequence;Ljava/lang/String;ZILjava/lang/Object;)Lkotlin/sequences/Sequence;
2626
public static final fun filterByNamePath (Lkotlin/sequences/Sequence;Ljava/lang/String;Z)Lkotlin/sequences/Sequence;
2727
public static synthetic fun filterByNamePath$default (Lkotlin/sequences/Sequence;Ljava/lang/String;ZILjava/lang/Object;)Lkotlin/sequences/Sequence;
28+
public static final fun multipleSet (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;Ljava/util/Set;Z)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
29+
public static synthetic fun multipleSet$default (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;Ljava/util/Set;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
2830
public static final fun skipBuildAndCacheDirs (Lkotlin/io/FileTreeWalk;)Lkotlin/io/FileTreeWalk;
2931
public static final fun skipBuildAndCacheDirs (Lkotlin/io/path/FileVisitorBuilder;)V
3032
public static final fun walkEachFile (Ljava/nio/file/Path;IZLkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
@@ -49,6 +51,11 @@ public final class slack/cli/CommandFactoryKt {
4951
public static synthetic fun runCommand$default ([Ljava/lang/String;ZILjava/lang/Object;)V
5052
}
5153

54+
public final class slack/cli/Playground {
55+
public static final fun main ()V
56+
public static synthetic fun main ([Ljava/lang/String;)V
57+
}
58+
5259
public final class slack/cli/Toml {
5360
public static final field INSTANCE Lslack/cli/Toml;
5461
public final fun parseVersion (Ljava/io/File;)Ljava/util/Map;
@@ -3463,6 +3470,21 @@ public final class slack/cli/gradle/GradleSettingsVerifierCli$Factory : slack/cl
34633470
public fun getKey ()Ljava/lang/String;
34643471
}
34653472

3473+
public final class slack/cli/gradle/GradleTestFixturesMigratorCli : com/github/ajalt/clikt/core/CliktCommand {
3474+
public static final field ANDROID_TEST_FIXTURES_BLOCK Ljava/lang/String;
3475+
public static final field DESCRIPTION Ljava/lang/String;
3476+
public static final field JAVA_FIXTURES_BLOCK Ljava/lang/String;
3477+
public fun <init> ()V
3478+
public fun run ()V
3479+
}
3480+
3481+
public final class slack/cli/gradle/GradleTestFixturesMigratorCli$Factory : slack/cli/CommandFactory {
3482+
public fun <init> ()V
3483+
public fun create ()Lcom/github/ajalt/clikt/core/CliktCommand;
3484+
public fun getDescription ()Ljava/lang/String;
3485+
public fun getKey ()Ljava/lang/String;
3486+
}
3487+
34663488
public final class slack/cli/lint/LintBaselineMergerCli : com/github/ajalt/clikt/core/CliktCommand {
34673489
public static final field DESCRIPTION Ljava/lang/String;
34683490
public fun <init> ()V

src/main/kotlin/slack/cli/CliUtil.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
package slack.cli
1919

20+
import com.github.ajalt.clikt.core.MissingOption
21+
import com.github.ajalt.clikt.parameters.options.NullableOption
22+
import com.github.ajalt.clikt.parameters.options.OptionWithValues
23+
import com.github.ajalt.clikt.parameters.options.transformAll
2024
import java.io.File
2125
import java.nio.file.FileVisitResult
2226
import java.nio.file.Path
@@ -127,3 +131,31 @@ private fun List<String>.padNewline(): List<String> {
127131
val noEmpties = dropLastWhile { it.isBlank() }
128132
return noEmpties + ""
129133
}
134+
135+
/**
136+
* Make the option return a set of calls; each item in the set is the value of one call.
137+
*
138+
* If the option is never called, the set will be empty. This must be applied after all other
139+
* transforms.
140+
*
141+
* ### Example:
142+
* ```
143+
* val opt: Set<Pair<Int, Int>> by option().int().pair().multipleSet()
144+
* ```
145+
*
146+
* @param default The value to use if the option is not supplied. Defaults to an empty set.
147+
* @param required If true, [default] is ignored and [MissingOption] will be thrown if no instances
148+
* of the option are present on the command line.
149+
*/
150+
public fun <EachT, ValueT> NullableOption<EachT, ValueT>.multipleSet(
151+
default: Set<EachT> = emptySet(),
152+
required: Boolean = false,
153+
): OptionWithValues<Set<EachT>, EachT, ValueT> {
154+
return transformAll(showAsRequired = required) {
155+
when {
156+
it.isEmpty() && required -> throw MissingOption(option)
157+
it.isEmpty() && !required -> default
158+
else -> it
159+
}.toSet()
160+
}
161+
}

0 commit comments

Comments
 (0)