SeanutSwift/Sources/Commands/Login.swift

35 lines
1,018 B
Swift
Raw Normal View History

2024-02-16 14:58:42 -05:00
// Login.swift
import Foundation
import ArgumentParser
import JellyfinAPI
extension Seanut {
struct LoginCommand: AsyncParsableCommand {
static var configuration = CommandConfiguration(
commandName: "login",
abstract: "Logs in as specified user to specified jellyfin server. caches access token for later invocations"
)
@OptionGroup var options: Seanut.CommonArguments
@Option(name: .shortAndLong, help: "username for the jellyfin server")
var username: String
@Option(name: .shortAndLong, help: "password for the jellyfin server")
var password: String?
mutating func run() async {
let client = JellyfinClient(
configuration: Seanut.generateJellyfinConfiguration(url: options.domain.toURL()!)
)
await Seanut.getAccessToken(
client: client,
username: username,
password: password
)
}
}
}