diff --git a/gradle.properties b/gradle.properties index 7827924..e668577 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ kotlin.code.style=official -version=3.0.0-alpha.1 +version=3.0.0-alpha.2 diff --git a/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt b/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt index a8ec75f..1e03fa9 100644 --- a/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt +++ b/src/main/kotlin/com/mineinabyss/keepup/commands/ConfigCommand.kt @@ -65,9 +65,10 @@ class ConfigCommand : CliktCommand(name = "config", help = "Syncs local config f t.println("${MSG.error} Config not found: $include") return }) - val included = inventory.getOrCreateConfigs(config.include) - val reduced = ConfigDefinition.reduce(included + config) + val included = inventory.getOrCreateConfigs(include) + val reduced = ConfigDefinition.reduce(included) + t.println("${MSG.info} Included paths: ${reduced.copyPaths}") val paths = reduced.copyPaths.map { sourceRoot / it } val tree = ConfigTreeBuilder() diff --git a/src/main/kotlin/com/mineinabyss/keepup/config/Inventory.kt b/src/main/kotlin/com/mineinabyss/keepup/config/Inventory.kt index d586bcf..dcb9a30 100644 --- a/src/main/kotlin/com/mineinabyss/keepup/config/Inventory.kt +++ b/src/main/kotlin/com/mineinabyss/keepup/config/Inventory.kt @@ -10,15 +10,23 @@ import kotlinx.serialization.builtins.serializer class Inventory( val configs: Map, ) { - fun getOrCreateConfigs(names: Iterable): List { + fun getOrCreateConfigs(name: String): List { val global = configs["global"] - return listOfNotNull(global) + names.map { - configs[it] ?: ConfigDefinition( - copyPaths = listOf(it), - ) + val includes = getDeepIncludes(names = listOf(name)).distinct().reversed() + return listOfNotNull(global) + includes.map { + configs[it] ?: ConfigDefinition(copyPaths = listOf(it)) } } + tailrec fun getDeepIncludes(acc: MutableList = mutableListOf(), names: List): List { + if (names.isEmpty()) return acc + val namesSet = names.toSet() + val nonCyclicNames = names - acc.filter { it in namesSet }.toSet() + acc.addAll(nonCyclicNames) + val newNames = nonCyclicNames.flatMap { configs[it]?.include?.reversed() ?: emptyList() } + return getDeepIncludes(acc, newNames) + } + object Serializer : InnerSerializer, Inventory>( "Inventory", MapSerializer(String.serializer(), ConfigDefinition.serializer()), diff --git a/src/main/kotlin/com/mineinabyss/keepup/config/templating/Templater.kt b/src/main/kotlin/com/mineinabyss/keepup/config/templating/Templater.kt index 446073a..15e7e48 100644 --- a/src/main/kotlin/com/mineinabyss/keepup/config/templating/Templater.kt +++ b/src/main/kotlin/com/mineinabyss/keepup/config/templating/Templater.kt @@ -4,7 +4,7 @@ import io.pebbletemplates.pebble.PebbleEngine import java.io.StringWriter class Templater { - val pebble = PebbleEngine.Builder().build() + val pebble = PebbleEngine.Builder().autoEscaping(false).build() fun template(input: String, variables: Map): Result { val writer = StringWriter()