Skip to content

Commit

Permalink
refactor: Structural output list ios versions (#1924)
Browse files Browse the repository at this point in the history
Fixes #1862 

## Test Plan
> How do we know the code works?

1. Run flank ```flank  ios versions list```
2. See output

```
┌───────────────┬───────────────┬───────────────┬─────────┬──────────────────────────────┐
│ OS_VERSION_ID │ MAJOR_VERSION │ MINOR_VERSION │  TAGS   │ SUPPORTED_XCODE_VERSION_IDS  │
├───────────────┼───────────────┼───────────────┼─────────┼──────────────────────────────┤
│     10.3      │      10       │       3       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     11.2      │      11       │       2       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     11.4      │      11       │       4       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     12.0      │      12       │ UNKNOWN       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     12.1      │      12       │       1       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     12.2      │      12       │       2       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     12.3      │      12       │       3       │         │ 10.3, 11.6, 11.7, 12.1, 12.3 │
│     12.4      │      12       │       4       │         │ 11.6, 11.7, 12.1, 12.3       │
│     13.2      │      13       │       2       │         │ 11.6, 11.7, 12.1, 12.3       │
│     13.3      │      13       │       3       │         │ 11.6, 11.7, 12.1, 12.3       │
│     13.6      │      13       │       6       │         │ 11.6, 11.7, 12.1, 12.3       │
│     14.1      │      14       │       1       │ default │ 12.1, 12.3                   │
└───────────────┴───────────────┴───────────────┴─────────┴──────────────────────────────┘

Total run duration: 0m  4s
```

## Checklist

- [X] Refactored
  • Loading branch information
adamfilipow92 authored May 12, 2021
1 parent 8f745b7 commit cfb302e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object FetchGoogleTestEnvironmentIos :
TestEnvironment.Ios.Fetch,
(String) -> TestEnvironment.Ios by { projectId ->
TestEnvironment.Ios(
osVersions = fetchIosOsVersion(projectId),
osVersions = fetchIosOsVersion(projectId).list,
models = fetchDeviceModelIos(projectId).list,
locales = fetchLocales(Locale.Identity(projectId, Platform.IOS)),
softwareCatalog = fetchSoftwareCatalog(),
Expand Down
6 changes: 4 additions & 2 deletions test_runner/src/main/kotlin/ftl/adapter/IosVersionsFetch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import ftl.client.google.iosOsVersions

object IosVersionsFetch :
OsVersion.Ios.Fetch,
(String) -> List<OsVersion.Ios> by {
iosOsVersions(it).toApiModel()
(String) -> OsVersion.Ios.Available by {
iosOsVersions(it).toApiModel().available()
}

private fun List<OsVersion.Ios>.available() = OsVersion.Ios.Available(this)
6 changes: 5 additions & 1 deletion test_runner/src/main/kotlin/ftl/api/OsVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ object OsVersion {
val supportedXcodeVersionIds: List<String>?,
val tags: List<String>?,
) {
interface Fetch : (String) -> List<Ios>
data class Available(
val list: List<Ios>
)

interface Fetch : (String) -> Available
}

data class Distribution(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DescribeIosVersions : Output {
operator fun DescribeIosVersions.invoke() {
if (versionId.isBlank()) throw FlankConfigurationError("Argument VERSION_ID must be specified.")
fetchIosOsVersion(IosArgs.loadOrDefault(Paths.get(configPath)).project)
.list
.find { it.id == versionId }
?.out()
?: throw FlankGeneralError("ERROR: '$versionId' is not a valid OS version")
Expand Down
8 changes: 4 additions & 4 deletions test_runner/src/main/kotlin/ftl/domain/ListIosVersions.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ftl.domain

import flank.common.logLn
import ftl.api.fetchIosOsVersion
import ftl.args.IosArgs
import ftl.client.google.IosCatalog
import ftl.presentation.Output
import java.nio.file.Paths

interface ListIosVersions {
interface ListIosVersions : Output {
var configPath: String
}

operator fun ListIosVersions.invoke() {
logLn(IosCatalog.softwareVersionsAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project))
fetchIosOsVersion(IosArgs.loadOrDefault(Paths.get(configPath)).project).out()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ftl.environment.tagToSystemOutColorMapper
import ftl.util.applyColorsUsing
import ftl.util.buildTable

fun OsVersion.Ios.Available.toCliTable() = list.toCliTable()

fun List<OsVersion.Ios>.toCliTable() = createTestEnvironmentInfo().createIOsSoftwareVersionsTable()

private fun List<OsVersion.Ios>.createTestEnvironmentInfo() =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ftl.presentation.cli.firebase.test.ios.versions

import ftl.api.OsVersion
import ftl.config.FtlConstants
import ftl.domain.ListIosVersions
import ftl.domain.invoke
import ftl.environment.ios.toCliTable
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine

@CommandLine.Command(
Expand Down Expand Up @@ -34,4 +38,11 @@ class IosVersionsListCommand :
var usageHelpRequested: Boolean = false

override fun run() = invoke()

override val out = outputLogger {
when (this) {
is OsVersion.Ios.Available -> toCliTable()
else -> throwUnknownType()
}
}
}

0 comments on commit cfb302e

Please sign in to comment.