Update code for Clikt 5
Some checks failed
Repo / Label merge conflict / Triage (push) Failing after 1s
SDK / Documentation / Lint (push) Failing after 1s
SDK / Documentation / Build Vitepress (push) Failing after 1s
SDK / Documentation / Build Dokka (push) Failing after 1s
SDK / Documentation / Deploy (push) Has been skipped
SDK / Lint / Lint (push) Failing after 1s
SDK / Publish / Publish (push) Failing after 1s
SDK / Test / Test (17) (push) Failing after 1s
SDK / Test / Test (21) (push) Failing after 1s
SDK / Test / Validate binary compatibility (push) Failing after 1s
SDK / Test / Verify OpenAPI sources (push) Failing after 1s
SDK / Unstable branch / Update (push) Failing after 1s

This commit is contained in:
Niels van Velzen 2024-09-22 10:27:03 +02:00 committed by Niels van Velzen
parent 0184fc3b73
commit 3613fa5545
8 changed files with 26 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package org.jellyfin.openapi
import com.github.ajalt.clikt.core.main
import org.jellyfin.openapi.cli.MainCommand
import org.jellyfin.openapi.hooks.hooksModule
import org.koin.core.context.startKoin

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.main
import com.github.ajalt.clikt.core.subcommands
import org.jellyfin.sample.cli.command.Discover
import org.jellyfin.sample.cli.command.Libraries
@ -27,6 +28,5 @@ fun main(args: Array<String>) {
subcommands(Users(jellyfin))
}
instance.main(args)
}

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli.command
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.default
import kotlinx.coroutines.flow.collect
@ -11,7 +12,7 @@ import org.jellyfin.sdk.Jellyfin
class Discover(
private val jellyfin: Jellyfin
) : CliktCommand("Discover servers on the local network") {
) : CliktCommand(name = "discover") {
private val logger by logger()
private val address by argument(
@ -19,6 +20,8 @@ class Discover(
help = "Address to discover servers for. \"local\" to discovery servers in the local network."
).default("local")
override fun help(context: Context): String = "Discover servers on the local network"
override fun run() = runBlocking {
if (address == "local") runLocal()
else runAddress(address)

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli.command
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import kotlinx.coroutines.runBlocking
import org.jellyfin.sample.cli.apiInstanceHolder
import org.jellyfin.sample.cli.logger
@ -9,10 +10,12 @@ import org.jellyfin.sdk.api.client.extensions.userViewsApi
class Libraries(
jellyfin: Jellyfin
) : CliktCommand("List all libraries") {
) : CliktCommand(name = "libraries") {
private val logger by logger()
private val api by apiInstanceHolder(jellyfin)
override fun help(context: Context): String = "List all libraries"
override fun run(): Unit = runBlocking {
val libraries by api.userViewsApi.getUserViews(includeHidden = false)

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli.command
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import kotlinx.coroutines.runBlocking
import org.jellyfin.sample.cli.apiInstanceHolder
import org.jellyfin.sample.cli.logger
@ -8,10 +9,12 @@ import org.jellyfin.sdk.Jellyfin
class Login(
jellyfin: Jellyfin
) : CliktCommand("Login to a given server and retrieve an access token") {
) : CliktCommand(name = "login") {
private val logger by logger()
private val api by apiInstanceHolder(jellyfin)
override fun help(context: Context): String = "Login to a given server and retrieve an access token"
override fun run() = runBlocking {
if (api.accessToken != null) logger.info(api.accessToken)
}

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli.command
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@ -15,10 +16,12 @@ import org.jellyfin.sdk.model.api.MediaType
class Observe(
jellyfin: Jellyfin,
) : CliktCommand("Create a WebSocket connection and listen to all events") {
) : CliktCommand(name = "observe") {
private val logger by logger()
private val api by apiInstanceHolder(jellyfin)
override fun help(context: Context): String = "Create a WebSocket connection and listen to all events"
override fun run(): Unit = runBlocking {
logger.info("Starting subscription")

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli.command
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import kotlinx.coroutines.runBlocking
@ -11,7 +12,7 @@ import org.jellyfin.sdk.api.client.extensions.systemApi
class Ping(
private val jellyfin: Jellyfin,
) : CliktCommand("Pings a given server and retrieve basic system information") {
) : CliktCommand(name = "ping") {
private val logger by logger()
private val server by serverOption()
private val extended by option(
@ -19,6 +20,8 @@ class Ping(
help = "Find servers based on input using recommended server algorithm"
).flag(default = false)
override fun help(context: Context): String = "Pings a given server and retrieve basic system information"
override fun run() = runBlocking {
if (extended) runExtended()
else runSimple()

View File

@ -1,6 +1,7 @@
package org.jellyfin.sample.cli.command
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import kotlinx.coroutines.runBlocking
import org.jellyfin.sample.cli.logger
import org.jellyfin.sample.cli.serverOption
@ -9,10 +10,12 @@ import org.jellyfin.sdk.api.client.extensions.userApi
class Users(
private val jellyfin: Jellyfin
) : CliktCommand("List all public users") {
) : CliktCommand(name = "users") {
private val logger by logger()
private val server by serverOption()
override fun help(context: Context): String = "List all public users"
override fun run() = runBlocking {
val api = jellyfin.createApi(baseUrl = server)