Skip to content

Commit

Permalink
modification
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloox authored and mergify-bot committed May 4, 2021
1 parent 60bae90 commit 3bc3fc9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ interface DescribeIosLocales : Output {
fun DescribeIosLocales.invoke() {
if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.")

fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS, locale)).out()
fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS, locale)).find {
it.id == locale
}?.out()
}
10 changes: 5 additions & 5 deletions test_runner/src/main/kotlin/ftl/environment/ListLocales.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ private const val NAME = "NAME"
private const val REGION = "REGION"

fun List<Locale>.getLocaleDescription(localeId: String) =
findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n")
findLocales(localeId)?.prepareDescription(localeId).orErrorMessage(localeId).plus("\n")

private fun List<Locale>.findLocales(localeId: String) = find { it.id == localeId }

private fun Locale.prepareDescription() = """
id: $id
name: $name
""".trimIndent().addRegionIfExist(region).addTagsIfExists(this)
fun Locale.prepareDescription(locale: String) = """
id: $id
name: $name
""".trimIndent().addRegionIfExist(region).addTagsIfExists(this).orErrorMessage(locale).plus("\n")

private fun String.addRegionIfExist(region: String?) =
if (!region.isNullOrEmpty()) StringBuilder(this).appendLine("\nregion: $region").trim().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ftl.api.Locale
import ftl.config.FtlConstants
import ftl.domain.DescribeIosLocales
import ftl.domain.invoke
import ftl.environment.getLocaleDescription
import ftl.environment.prepareDescription
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine
Expand Down Expand Up @@ -44,7 +44,7 @@ class IosLocalesDescribeCommand :

override val out = outputLogger {
when (this) {
is List<*> -> (this as List<Locale>).getLocaleDescription(locale)
is Locale -> prepareDescription(locale)
else -> throwUnknownType()
}
}
Expand Down

0 comments on commit 3bc3fc9

Please sign in to comment.