Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: Structural output list network profiles #1915

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions test_runner/src/main/kotlin/ftl/domain/ListNetworkProfiles.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package ftl.domain

import flank.common.logLn
import ftl.api.fetchNetworkProfiles
import ftl.environment.common.toCliTable
import ftl.presentation.Output

interface ListNetworkProfiles
interface ListNetworkProfiles : Output

operator fun ListNetworkProfiles.invoke() {
// TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728
logLn("fetching available network profiles...")
logLn(fetchNetworkProfiles().toCliTable())
"fetching available network profiles...".out()
fetchNetworkProfiles().out()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.util.asListOrNull
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -30,11 +31,6 @@ class AndroidLocalesListCommand :
)
override var configPath: String = FtlConstants.defaultAndroidConfig

override val out = outputLogger {
@Suppress("UNCHECKED_CAST")
(this as? List<Locale>)?.toCliTable() ?: throwUnknownType()
}

@CommandLine.Option(
names = ["-h", "--help"],
usageHelp = true,
Expand All @@ -43,4 +39,8 @@ class AndroidLocalesListCommand :
var usageHelpRequested: Boolean = false

override fun run() = invoke()

override val out = outputLogger {
asListOrNull<Locale>()?.toCliTable() ?: throwUnknownType()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ftl.domain.ListAndroidOrientations
import ftl.domain.invoke
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.util.asListOrNull
import picocli.CommandLine

@CommandLine.Command(
Expand Down Expand Up @@ -39,7 +40,6 @@ class AndroidOrientationsListCommand :
override fun run() = invoke()

override val out = outputLogger {
@Suppress("UNCHECKED_CAST")
(this as? List<Orientation>)?.toCliTable() ?: throwUnknownType()
asListOrNull<Orientation>()?.toCliTable() ?: throwUnknownType()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package ftl.presentation.cli.firebase.test.environment

import ftl.api.TestEnvironment
import ftl.environment.android.toCliTable
import ftl.environment.common.toCliTable
import ftl.environment.ios.toCliTable
import ftl.presentation.cli.firebase.test.android.orientations.toCliTable
import ftl.presentation.cli.firebase.test.ipblocks.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.presentation.cli.firebase.test.networkprofiles.toCliTable
import ftl.presentation.cli.firebase.test.providedsoftware.toCliTable

fun TestEnvironment.Android.prepareOutputString() = buildString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine

@Suppress("UNCHECKED_CAST")
@CommandLine.Command(
name = "describe",
headerHeading = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.util.asListOrNull
import picocli.CommandLine

@CommandLine.Command(
Expand Down Expand Up @@ -40,7 +41,6 @@ class IosLocalesListCommand :
override fun run() = invoke()

override val out = outputLogger {
@Suppress("UNCHECKED_CAST")
(this as? List<Locale>)?.toCliTable() ?: throwUnknownType()
asListOrNull<Locale>()?.toCliTable() ?: throwUnknownType()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import ftl.config.FtlConstants
import ftl.domain.ListIosOrientations
import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.android.orientations.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.util.asListOrNull
import picocli.CommandLine

@CommandLine.Command(
Expand Down Expand Up @@ -40,7 +42,6 @@ class IosOrientationsListCommand :
override fun run() = invoke()

override val out = outputLogger {
@Suppress("UNCHECKED_CAST")
(this as? List<Orientation>)?.toCliTable() ?: throwUnknownType()
asListOrNull<Orientation>()?.toCliTable() ?: throwUnknownType()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ftl.environment.common
package ftl.presentation.cli.firebase.test.networkprofiles

import ftl.api.NetworkProfile
import ftl.environment.TestEnvironmentInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package ftl.presentation.cli.firebase.test.networkprofiles

import ftl.api.NetworkProfile
import ftl.domain.ListNetworkProfiles
import ftl.domain.invoke
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.util.asList
import ftl.util.asListOrNull
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -19,4 +24,12 @@ class NetworkProfilesListCommand :
Runnable,
ListNetworkProfiles {
override fun run() = invoke()

override val out = outputLogger {
when {
asListOrNull<NetworkProfile>() != null -> asList<NetworkProfile>().toCliTable()
this is String -> this
else -> throwUnknownType()
}
}
}
7 changes: 7 additions & 0 deletions test_runner/src/main/kotlin/ftl/util/CastingUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ftl.util

@Suppress("UNCHECKED_CAST")
fun <T> Any.asList(): List<T> = this as List<T>

@Suppress("UNCHECKED_CAST")
fun <T> Any.asListOrNull(): List<T>? = this as? List<T>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ftl.cli.firebase.test.networkprofiles

import ftl.api.NetworkProfile
import ftl.api.fetchNetworkProfiles
import ftl.environment.common.toCliTable
import ftl.presentation.cli.firebase.test.networkprofiles.NetworkProfilesListCommand
import ftl.presentation.cli.firebase.test.networkprofiles.toCliTable
import io.mockk.every
import io.mockk.mockkStatic
import io.mockk.unmockkAll
Expand Down