Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: Describe ios locales #1886

Merged
merged 9 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/api/Locale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class Locale(

data class Identity(
val projectId: String,
val platform: Platform
val platform: Platform,
val locale: String? = null,
)

interface Fetch : (Identity) -> List<Locale>
Expand Down
13 changes: 7 additions & 6 deletions test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package ftl.domain

import flank.common.log
import ftl.api.Locale.Identity
import ftl.api.Platform
import ftl.api.fetchLocales
import ftl.args.IosArgs
import ftl.environment.getLocaleDescription
import ftl.presentation.Output
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.FlankGeneralError
import java.nio.file.Paths

interface DescribeIosLocales {
interface DescribeIosLocales : Output {
val locale: String
val configPath: String
}

fun DescribeIosLocales.invoke() {
if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.")
log(
fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS)).getLocaleDescription(locale)
)

fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS, locale)).find {
it.id == locale
}?.out() ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale")
}
6 changes: 3 additions & 3 deletions test_runner/src/main/kotlin/ftl/environment/ListLocales.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fun List<Locale>.getLocaleDescription(localeId: String) =

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

private fun Locale.prepareDescription() = """
id: $id
name: $name
fun Locale.prepareDescription() = """
id: $id
name: $name
""".trimIndent().addRegionIfExist(region).addTagsIfExists(this)

private fun String.addRegionIfExist(region: String?) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package ftl.presentation.cli.firebase.test.ios.configuration

import ftl.api.Locale
import ftl.config.FtlConstants
import ftl.domain.DescribeIosLocales
import ftl.domain.invoke
import ftl.environment.prepareDescription
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine

@Suppress("UNCHECKED_CAST")
@CommandLine.Command(
name = "describe",
headerHeading = "",
Expand Down Expand Up @@ -37,5 +42,12 @@ class IosLocalesDescribeCommand :
)
override var configPath: String = FtlConstants.defaultIosConfig

override val out = outputLogger {
when (this) {
is Locale -> prepareDescription()
else -> throwUnknownType()
}
}

override fun run() = invoke()
}