From f2eebd95461f2c8fbefd578181340fa8583e75cf Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 6 May 2021 09:17:07 +0200 Subject: [PATCH] Iteration 1 --- .../ftl/domain/DescribeAndroidLocales.kt | 20 ++++++++----------- .../locales/AndroidLocalesDescribeCommand.kt | 11 ++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt index 8487243bd8..8095a47341 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt @@ -1,27 +1,23 @@ package ftl.domain -import flank.common.log -import ftl.api.Locale +import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchLocales import ftl.args.AndroidArgs -import ftl.presentation.cli.firebase.test.locale.getLocaleDescription +import ftl.presentation.Output import ftl.run.exception.FlankConfigurationError +import ftl.run.exception.FlankGeneralError import java.nio.file.Paths -interface DescribeAndroidLocales { +interface DescribeAndroidLocales : Output { val locale: String val configPath: String } fun DescribeAndroidLocales.invoke() { if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.") - log( - fetchLocales( - Locale.Identity( - AndroidArgs.loadOrDefault(Paths.get(configPath)).project, - Platform.ANDROID - ) - ).getLocaleDescription(locale) - ) + + fetchLocales(Identity(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, Platform.ANDROID)).find { + it.id == locale + }?.out() ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale") } diff --git a/test_runner/src/main/kotlin/ftl/presentation/cli/firebase/test/android/locales/AndroidLocalesDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/presentation/cli/firebase/test/android/locales/AndroidLocalesDescribeCommand.kt index 8eed5d2be3..ab0ec369b4 100644 --- a/test_runner/src/main/kotlin/ftl/presentation/cli/firebase/test/android/locales/AndroidLocalesDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/presentation/cli/firebase/test/android/locales/AndroidLocalesDescribeCommand.kt @@ -1,8 +1,12 @@ package ftl.presentation.cli.firebase.test.android.locales +import ftl.api.Locale import ftl.config.FtlConstants import ftl.domain.DescribeAndroidLocales import ftl.domain.invoke +import ftl.presentation.cli.firebase.test.locale.prepareDescription +import ftl.presentation.outputLogger +import ftl.presentation.throwUnknownType import picocli.CommandLine @CommandLine.Command( @@ -37,5 +41,12 @@ class AndroidLocalesDescribeCommand : ) override var configPath: String = FtlConstants.defaultAndroidConfig + override val out = outputLogger { + when (this) { + is Locale -> prepareDescription() + else -> throwUnknownType() + } + } + override fun run() = invoke() }