Skip to content

Commit

Permalink
Extract logic from cli to domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral committed Mar 22, 2021
1 parent 6528ab5 commit f586f9f
Show file tree
Hide file tree
Showing 71 changed files with 918 additions and 507 deletions.
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/#Command.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()
}
13 changes: 7 additions & 6 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,12 @@ 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"])
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() }
}
14 changes: 3 additions & 11 deletions test_runner/src/main/kotlin/ftl/cli/firebase/TestCommand.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package ftl.cli.firebase

import ftl.cli.firebase.test.AndroidCommand
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.cli.firebase.test.*
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -20,8 +16,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
@@ -1,13 +1,7 @@
package ftl.cli.firebase.test

import ftl.cli.firebase.test.android.AndroidDoctorCommand
import ftl.cli.firebase.test.android.AndroidLocalesCommand
import ftl.cli.firebase.test.android.AndroidModelsCommand
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.cli.firebase.test.android.*
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -24,8 +18,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
@@ -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
16 changes: 3 additions & 13 deletions test_runner/src/main/kotlin/ftl/cli/firebase/test/IosCommand.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package ftl.cli.firebase.test

import ftl.cli.firebase.test.ios.IosDoctorCommand
import ftl.cli.firebase.test.ios.IosLocalesCommand
import ftl.cli.firebase.test.ios.IosModelsCommand
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.cli.firebase.test.ios.*
import ftl.util.PrintHelp
import picocli.CommandLine.Command

@Command(
Expand All @@ -24,8 +18,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

0 comments on commit f586f9f

Please # to comment.