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: Extract logic from cli to domain #1718

Merged
merged 6 commits into from
Mar 25, 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
8 changes: 2 additions & 6 deletions test_runner/src/main/kotlin/ftl/cli/AuthCommand.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ftl.cli

import ftl.cli.auth.LoginCommand
import picocli.CommandLine
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -13,8 +13,4 @@ import picocli.CommandLine.Command
],
usageHelpAutoWidth = true
)
class AuthCommand : Runnable {
override fun run() {
CommandLine.usage(AuthCommand(), System.out)
}
}
class AuthCommand : PrintHelp
8 changes: 2 additions & 6 deletions test_runner/src/main/kotlin/ftl/cli/FirebaseCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ftl.cli
import ftl.cli.firebase.CancelCommand
import ftl.cli.firebase.RefreshCommand
import ftl.cli.firebase.TestCommand
import picocli.CommandLine
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -16,8 +16,4 @@ import picocli.CommandLine.Command
],
usageHelpAutoWidth = true
)
class FirebaseCommand : Runnable {
override fun run() {
CommandLine.usage(FirebaseCommand(), System.out)
}
}
class FirebaseCommand : PrintHelp
12 changes: 7 additions & 5 deletions test_runner/src/main/kotlin/ftl/cli/auth/LoginCommand.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.auth

import ftl.gc.UserAuth
import ftl.domain.LoginGoogleAccount
import ftl.domain.invoke
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -15,15 +16,16 @@ import picocli.CommandLine
description = ["""Authenticates using your user account. For CI, a service account is recommended."""],
usageHelpAutoWidth = true
)
class LoginCommand : Runnable {
override fun run() {
UserAuth().request()
}
class LoginCommand :
Runnable,
LoginGoogleAccount {

@CommandLine.Option(
names = ["-h", "--help"],
usageHelp = true,
description = ["Prints this help message"]
)
var usageHelpRequested: Boolean = false

override fun run() = invoke()
}
19 changes: 12 additions & 7 deletions test_runner/src/main/kotlin/ftl/cli/firebase/CancelCommand.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ftl.cli.firebase

import ftl.args.AndroidArgs
import ftl.run.cancelLastRun
import ftl.domain.CancelLastRun
import ftl.domain.invoke
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -20,11 +20,16 @@ Reads in the matrix_ids.json file. Cancels any incomplete matrices.
],
usageHelpAutoWidth = true
)
class CancelCommand : Runnable {
override fun run() {
cancelLastRun(AndroidArgs.default())
}
class CancelCommand :
Runnable,
CancelLastRun {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"])
@CommandLine.Option(
names = ["-h", "--help"],
usageHelp = true,
description = ["Prints this help message"]
)
var usageHelpRequested: Boolean = false

override fun run() = invoke()
}
24 changes: 12 additions & 12 deletions test_runner/src/main/kotlin/ftl/cli/firebase/RefreshCommand.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ftl.cli.firebase

import ftl.args.AndroidArgs
import ftl.run.refreshLastRun
import ftl.domain.RefreshLastRun
import ftl.domain.invoke
import kotlinx.coroutines.runBlocking
import picocli.CommandLine.Command
import picocli.CommandLine.Option
Expand All @@ -22,16 +22,16 @@ Reads in the matrix_ids.json file. Refreshes any incomplete matrices.
],
usageHelpAutoWidth = true
)
class RefreshCommand : Runnable {
override fun run() {
runBlocking {
refreshLastRun(
currentArgs = AndroidArgs.default(),
testShardChunks = emptyList()
)
}
}
class RefreshCommand :
Runnable,
RefreshLastRun {

@Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"])
@Option(
names = ["-h", "--help"],
usageHelp = true,
description = ["Prints this help message"]
)
var usageHelpRequested: Boolean = false

override fun run() = runBlocking { invoke() }
}
8 changes: 2 additions & 6 deletions test_runner/src/main/kotlin/ftl/cli/firebase/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ftl.cli.firebase.test.IPBlocksCommand
import ftl.cli.firebase.test.IosCommand
import ftl.cli.firebase.test.NetworkProfilesCommand
import ftl.cli.firebase.test.ProvidedSoftwareCommand
import picocli.CommandLine
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -20,8 +20,4 @@ import picocli.CommandLine.Command
],
usageHelpAutoWidth = true
)
class TestCommand : Runnable {
override fun run() {
CommandLine.usage(TestCommand(), System.out)
}
}
class TestCommand : PrintHelp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ftl.cli.firebase.test.android.AndroidOrientationsCommand
import ftl.cli.firebase.test.android.AndroidRunCommand
import ftl.cli.firebase.test.android.AndroidTestEnvironmentCommand
import ftl.cli.firebase.test.android.AndroidVersionsCommand
import picocli.CommandLine
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -24,8 +24,4 @@ import picocli.CommandLine.Command
],
usageHelpAutoWidth = true
)
class AndroidCommand : Runnable {
override fun run() {
CommandLine.usage(AndroidCommand(), System.out)
}
}
class AndroidCommand : PrintHelp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ftl.config.common.CommonGcloudConfig
import ftl.config.common.addDevice
import picocli.CommandLine

abstract class CommonRunCommand {
abstract class CommonRunCommand : Runnable {

@CommandLine.Mixin
private val commonGcloudConfig = CommonGcloudConfig()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.firebase.test

import ftl.cli.firebase.test.ipblocks.IPBlocksListCommand
import ftl.util.PrintHelp
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -10,8 +11,4 @@ import picocli.CommandLine
header = ["Explore IP blocks used by Firebase Test Lab devices."],
usageHelpAutoWidth = true
)
class IPBlocksCommand : Runnable {
override fun run() {
CommandLine.usage(IPBlocksCommand(), System.out)
}
}
class IPBlocksCommand : PrintHelp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ftl.cli.firebase.test.ios.IosOrientationsCommand
import ftl.cli.firebase.test.ios.IosRunCommand
import ftl.cli.firebase.test.ios.IosTestEnvironmentCommand
import ftl.cli.firebase.test.ios.IosVersionsCommand
import picocli.CommandLine
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -24,8 +24,4 @@ import picocli.CommandLine.Command
],
usageHelpAutoWidth = true
)
class IosCommand : Runnable {
override fun run() {
CommandLine.usage(IosCommand(), System.out)
}
}
class IosCommand : PrintHelp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.cli.firebase.test

import ftl.cli.firebase.test.networkprofiles.NetworkProfilesDescribeCommand
import ftl.cli.firebase.test.networkprofiles.NetworkProfilesListCommand
import ftl.util.PrintHelp
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -14,8 +15,4 @@ import picocli.CommandLine
header = ["Explore network profiles available for testing."],
usageHelpAutoWidth = true
)
class NetworkProfilesCommand : Runnable {
override fun run() {
CommandLine.usage(NetworkProfilesCommand(), System.out)
}
}
class NetworkProfilesCommand : PrintHelp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.firebase.test

import ftl.cli.firebase.test.providedsoftware.ProvidedSoftwareListCommand
import ftl.util.PrintHelp
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -11,8 +12,4 @@ import picocli.CommandLine
],
usageHelpAutoWidth = true
)
class ProvidedSoftwareCommand : Runnable {
override fun run() {
CommandLine.usage(ProvidedSoftwareCommand(), System.out)
}
}
class ProvidedSoftwareCommand : PrintHelp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ftl.cli.firebase.test.android

import ftl.args.AndroidArgs
import ftl.cli.firebase.test.processValidation
import ftl.config.FtlConstants
import ftl.doctor.validateYaml
import ftl.domain.RunDoctorAndroid
import ftl.domain.invoke
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import java.nio.file.Paths

@Command(
name = "doctor",
Expand All @@ -23,19 +21,28 @@ import java.nio.file.Paths
],
usageHelpAutoWidth = true
)
class AndroidDoctorCommand : Runnable {
override fun run() {
val ymlPath = Paths.get(configPath)
val validationResult = validateYaml(AndroidArgs, ymlPath)
processValidation(validationResult, fix, ymlPath)
}
class AndroidDoctorCommand :
Runnable,
RunDoctorAndroid {

@Option(names = ["-c", "--config"], description = ["YAML config file path"])
var configPath: String = FtlConstants.defaultAndroidConfig

@Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"])
@Option(
names = ["-h", "--help"],
usageHelp = true,
description = ["Prints this help message"]
)
var usageHelpRequested: Boolean = false

@Option(names = ["-f", "--fix"], description = ["Auto fix flank YAML file"])
var fix: Boolean = false
@Option(
names = ["-c", "--config"],
description = ["YAML config file path"]
)
override var configPath: String = FtlConstants.defaultAndroidConfig

@Option(
names = ["-f", "--fix"],
description = ["Auto fix flank YAML file"]
)
override var fix: Boolean = false

override fun run() = invoke()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.cli.firebase.test.android

import ftl.cli.firebase.test.android.configuration.AndroidLocalesDescribeCommand
import ftl.cli.firebase.test.android.configuration.AndroidLocalesListCommand
import ftl.util.PrintHelp
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -16,8 +17,4 @@ import picocli.CommandLine
subcommands = [AndroidLocalesListCommand::class, AndroidLocalesDescribeCommand::class],
usageHelpAutoWidth = true
)
class AndroidLocalesCommand : Runnable {
override fun run() {
CommandLine.usage(AndroidLocalesCommand(), System.out)
}
}
class AndroidLocalesCommand : PrintHelp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.cli.firebase.test.android

import ftl.cli.firebase.test.android.models.AndroidModelDescribeCommand
import ftl.cli.firebase.test.android.models.AndroidModelsListCommand
import ftl.util.PrintHelp
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -16,8 +17,4 @@ import picocli.CommandLine
subcommands = [AndroidModelsListCommand::class, AndroidModelDescribeCommand::class],
usageHelpAutoWidth = true
)
class AndroidModelsCommand : Runnable {
override fun run() {
CommandLine.usage(AndroidModelsCommand(), System.out)
}
}
class AndroidModelsCommand : PrintHelp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.firebase.test.android

import ftl.cli.firebase.test.android.orientations.AndroidOrientationsListCommand
import ftl.util.PrintHelp
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -15,8 +16,4 @@ import picocli.CommandLine
subcommands = [AndroidOrientationsListCommand::class],
usageHelpAutoWidth = true
)
class AndroidOrientationsCommand : Runnable {
override fun run() {
CommandLine.usage(AndroidOrientationsCommand(), System.out)
}
}
class AndroidOrientationsCommand : PrintHelp
Loading