From 05fbd7d27449b968602d1bb67df0bb2fe38f46a9 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Fri, 11 Oct 2024 20:36:41 -0400 Subject: [PATCH] Use the appropriate extension for in-place conversion --- vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt b/vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt index 764ed68a..78ffa043 100644 --- a/vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt +++ b/vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt @@ -16,6 +16,7 @@ import org.w3c.dom.Document import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.File +import java.nio.file.Paths import javax.xml.parsers.DocumentBuilderFactory import kotlin.math.absoluteValue import kotlin.math.roundToInt @@ -59,7 +60,7 @@ class Vgo( } } else { inputs.zip(inputs) { a, b -> - Pair(File(a), File(b)) + } }.toMap() @@ -70,6 +71,24 @@ class Vgo( return handleFiles(inputOutputMap, writerOptions) } + private fun pairOutputs(): Map { + val inputFiles = options.input.map(::File) + return if (options.output.isNotEmpty()) { + inputFiles.zip(options.output.map(::File)).toMap() + } else { + inputFiles.mapIndexed { index, input -> + if (!input.isDirectory) { + val outputExtension = when (options.format) { + "svg" -> "svg" + "vd" -> "xml" + else -> input.extension + } + val outputFilePath = options.output.dropLastWhile { it != '.' } + outputExtension + } + }.toMap() + } + } + private fun handleFiles( inputOutputMap: Map, writerOptions: Set,