mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-11-26 23:50:32 +00:00
Use lazy injection for openapi-generator CLI
This commit is contained in:
parent
fcf130479a
commit
fdb1d9ce1f
@ -2,11 +2,11 @@ package org.jellyfin.openapi
|
||||
|
||||
import org.jellyfin.openapi.cli.MainCommand
|
||||
import org.jellyfin.openapi.hooks.hooksModule
|
||||
import org.koin.dsl.koinApplication
|
||||
import org.koin.core.context.startKoin
|
||||
|
||||
fun main(vararg args: String) {
|
||||
// Start Koin
|
||||
val koin = koinApplication { modules(mainModule, hooksModule) }.koin
|
||||
val koin = startKoin { modules(mainModule, hooksModule) }.koin
|
||||
|
||||
// Invoke Clikt to run requested command
|
||||
koin.get<MainCommand>().main(args)
|
||||
|
@ -69,7 +69,7 @@ val mainModule = module {
|
||||
single { DescriptionBuilder(getAll()) }
|
||||
|
||||
// CLI
|
||||
single { MainCommand(getAll(), getKoin()) }
|
||||
single { GenerateCommand(get()) } bind CliktCommand::class
|
||||
single { VerifyCommand(get()) } bind CliktCommand::class
|
||||
single { MainCommand() }
|
||||
single { GenerateCommand() } bind CliktCommand::class
|
||||
single { VerifyCommand() } bind CliktCommand::class
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package org.jellyfin.openapi.cli
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import org.koin.core.component.KoinComponent
|
||||
|
||||
@Suppress("UnnecessaryAbstractClass")
|
||||
abstract class BaseCommand : CliktCommand(), KoinComponent
|
@ -1,14 +1,14 @@
|
||||
package org.jellyfin.openapi.cli
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.options.required
|
||||
import com.github.ajalt.clikt.parameters.types.file
|
||||
import org.jellyfin.openapi.Generator
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class GenerateCommand : BaseCommand() {
|
||||
private val generator by inject<Generator>()
|
||||
|
||||
class GenerateCommand(
|
||||
private val generator: Generator,
|
||||
) : CliktCommand() {
|
||||
private val openApiFile by option(
|
||||
"--openApiFile",
|
||||
"-i",
|
||||
|
@ -5,12 +5,10 @@ import com.github.ajalt.clikt.core.subcommands
|
||||
import com.github.ajalt.clikt.parameters.options.flag
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import org.jellyfin.openapi.hooks.hooksModule
|
||||
import org.koin.core.Koin
|
||||
|
||||
class MainCommand(
|
||||
commands: List<CliktCommand>,
|
||||
private val koin: Koin,
|
||||
) : CliktCommand() {
|
||||
class MainCommand : BaseCommand() {
|
||||
private val commands by lazy { getKoin().getAll<CliktCommand>() }
|
||||
|
||||
private val noHooks by option(
|
||||
"--no-hooks",
|
||||
help = "Disable all hooks"
|
||||
@ -21,6 +19,6 @@ class MainCommand(
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
if (noHooks) koin.unloadModules(listOf(hooksModule))
|
||||
if (noHooks) getKoin().unloadModules(listOf(hooksModule))
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package org.jellyfin.openapi.cli
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.core.ProgramResult
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.options.required
|
||||
import com.github.ajalt.clikt.parameters.types.file
|
||||
import org.jellyfin.openapi.Generator
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class VerifyCommand : BaseCommand() {
|
||||
private val generator by inject<Generator>()
|
||||
|
||||
class VerifyCommand(
|
||||
private val generator: Generator,
|
||||
) : CliktCommand() {
|
||||
private val openApiFile by option(
|
||||
"--openApiFile",
|
||||
"-i",
|
||||
|
Loading…
Reference in New Issue
Block a user