From e95606a44e1299f690f48aca5e06b0d433e4d071 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Mon, 27 May 2024 12:10:55 -0400 Subject: [PATCH] chore(templates): Change some arguments to required options for clarity, since everything is a path --- gradle.properties | 2 +- .../keepup/commands/ConfigCommand.kt | 44 ++++++++++++++----- src/main/kotlin/helpers/Messages.kt | 1 + 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8209e04..e3e1e03 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ kotlin.code.style=official -version=2.0.3 +version=3.0.0-alpha.0 diff --git a/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt b/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt index 897515b..a8ec75f 100644 --- a/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt +++ b/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt @@ -4,7 +4,9 @@ import com.charleskorn.kaml.Yaml import com.charleskorn.kaml.decodeFromStream import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.arguments.argument -import com.github.ajalt.clikt.parameters.arguments.optional +import com.github.ajalt.clikt.parameters.options.defaultLazy +import com.github.ajalt.clikt.parameters.options.option +import com.github.ajalt.clikt.parameters.options.required import com.github.ajalt.clikt.parameters.types.path import com.github.ajalt.mordant.rendering.TextColors.brightGreen import com.github.ajalt.mordant.rendering.TextColors.gray @@ -25,30 +27,48 @@ import kotlin.time.DurationUnit import kotlin.time.TimeSource class ConfigCommand : CliktCommand(name = "config", help = "Syncs local config files to appropriate destinations") { - val targetName by argument(help = "Target server name for configs feature, used to figure out which configs to copy, etc...") - - val inventoryPath by argument(help = "Inventory file defining config options") + val include by argument( + "include", + help = "The config defined in inventory to sync" + ) + + val inventoryFile by option( + "-i", "--inventory", + help = "Inventory file defining config options" + ) .path(mustExist = true, canBeDir = false, mustBeReadable = true) + .required() + + val sourceRoot by option( + "-s", + "--source", + help = "Directory containing source configs to sync, defaults to directory of inventory" + ) + .path(mustExist = true, canBeFile = false, mustBeWritable = true) + .defaultLazy { inventoryFile.parent } - val destRoot by argument() + val destRoot by option("-d", "--dest", help = "Directory to sync configs to") .path(mustExist = true, canBeFile = false, mustBeWritable = true) + .required() - val templateCacheDir by argument(help = "Directory to cache template results, if unspecified will not templates .peb files") + val templateCacheDir by option( + "-t", "--template-cache", + help = "Directory to cache template results, if unspecified will not templates .peb files" + ) .path(mustExist = false, canBeFile = false, mustBeWritable = true) - .optional() @OptIn(ExperimentalStdlibApi::class) override fun run() { - t.println("${MSG.info} Running config sync for $targetName...") - val inventory = Yaml.default.decodeFromStream(inventoryPath.inputStream()) - val config = (inventory.configs[targetName] ?: run { - t.println("${MSG.error} Config not found: $targetName") + t.println("${MSG.info} Running config sync for $include...") + val inventory = Yaml.default.decodeFromStream(inventoryFile.inputStream()) + val config = (inventory.configs[include] ?: run { + t.println("${MSG.error} Config not found: $include") return }) val included = inventory.getOrCreateConfigs(config.include) val reduced = ConfigDefinition.reduce(included + config) - val paths = reduced.copyPaths.map { inventoryPath.parent / it } + val paths = reduced.copyPaths.map { sourceRoot / it } val tree = ConfigTreeBuilder() val destToSource = tree.destFilesForRoots(paths) diff --git a/src/main/kotlin/helpers/Messages.kt b/src/main/kotlin/helpers/Messages.kt index f73dea4..8f6fd50 100644 --- a/src/main/kotlin/helpers/Messages.kt +++ b/src/main/kotlin/helpers/Messages.kt @@ -20,6 +20,7 @@ object MSG { val rclone = brightBlue("[Rclone] ") val skipped = brightYellow("[Ignoring] ") + val warn = yellow("[Warn]") val error = red("[Error]") val delete = red("[Delete]") val copy = brightBlue("[Copy]")