package moe.odango.index.cli import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.options.option import kotlinx.coroutines.runBlocking import moe.odango.index.sync.AniDBTitleSync import java.io.File class AniDBSync : CliktCommand(name = "anidb",help = "Sync the titles from AniDB with the local database") { private val file by option(help = "Read from file instead of downloading") override fun run() { val sync = AniDBTitleSync() val file = file runBlocking { if (file == null) { sync.run() } else { val fileObj = File(file).takeIf { it.isFile } ?: throw RuntimeException("File doesn't exist") sync.syncWithFile(fileObj) } } } }