diff --git a/build.gradle.kts b/build.gradle.kts index 179f73b2..9d663322 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "org.veupathdb.lib" -version = "0.4.0" +version = "0.5.0" buildscript { dependencies { diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/Diamond.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/Diamond.kt index b8694142..0ed59e65 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/Diamond.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/Diamond.kt @@ -25,7 +25,7 @@ import org.veupathdb.lib.cli.diamond.commands.BlastX import org.veupathdb.lib.cli.diamond.commands.impl.BlastNImpl import org.veupathdb.lib.cli.diamond.commands.impl.BlastPImpl import org.veupathdb.lib.cli.diamond.commands.impl.BlastXImpl -import org.veupathdb.lib.cli.diamond.opts.output_format.cacheFormatFields +import org.veupathdb.lib.cli.diamond.opts.fields.output_format.cacheFormatFields import org.veupathdb.lib.jackson.Json import java.io.InputStream @@ -39,6 +39,18 @@ object Diamond { @DiamondExtras fun blastN(): BlastN = BlastNImpl() + /** + * Creates a new, blank [BlastN] CLI configuration instance and passes it to + * the given action before returning it. + * + * @param action Action which may be used to mutate the new `BlastN` instance. + * + * @return The new `BlastN` instance. + */ + @JvmStatic + @DiamondExtras + inline fun blastN(action: BlastN.() -> Unit): BlastN = blastN().apply(action) + /** * Attempts to parse the given JSON value as a [BlastN] CLI configuration. * @@ -96,6 +108,17 @@ object Diamond { @JvmStatic fun blastP(): BlastP = BlastPImpl() + /** + * Creates a new, blank [BlastP] CLI configuration instance and passes it to + * the given action before returning it. + * + * @param action Action which may be used to mutate the new `BlastP` instance. + * + * @return The new `BlastP` instance. + */ + @JvmStatic + inline fun blastP(action: BlastP.() -> Unit) = blastP().apply(action) + /** * Attempts to parse the given JSON value as a [BlastP] CLI configuration. * @@ -150,6 +173,17 @@ object Diamond { @JvmStatic fun blastX(): BlastX = BlastXImpl() + /** + * Creates a new, blank [BlastX] CLI configuration instance and passes it to + * the given action before returning it. + * + * @param action Action which may be used to mutate the new `BlastX` instance. + * + * @return The new `BlastX` instance. + */ + @JvmStatic + inline fun blastX(action: BlastX.() -> Unit) = blastX().apply(action) + /** * Attempts to parse the given JSON value as a [BlastX] CLI configuration. * diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/commands/DiamondCommandConfig.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/commands/DiamondCommandConfig.kt index 1bd28330..4c808353 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/commands/DiamondCommandConfig.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/commands/DiamondCommandConfig.kt @@ -1,10 +1,15 @@ package org.veupathdb.lib.cli.diamond.commands +import com.fasterxml.jackson.annotation.JsonGetter +import com.fasterxml.jackson.databind.annotation.JsonDeserialize import org.veupathdb.lib.cli.diamond.DiamondCommand +import org.veupathdb.lib.cli.diamond.util.DiamondCommandConfigDeserializer +@JsonDeserialize(using = DiamondCommandConfigDeserializer::class) sealed interface DiamondCommandConfig { /** * Diamond subcommand. */ + @get:JsonGetter("tool") val tool: DiamondCommand } diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/OutputFormatOptionContainer.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/OutputFormatOptionContainer.kt index 629dd5c9..471cc8f6 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/OutputFormatOptionContainer.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/OutputFormatOptionContainer.kt @@ -20,7 +20,7 @@ package org.veupathdb.lib.cli.diamond.opts import com.fasterxml.jackson.annotation.JsonGetter import com.fasterxml.jackson.annotation.JsonSetter import io.foxcapades.lib.cli.builder.flag.CliFlag -import org.veupathdb.lib.cli.diamond.opts.output_format.OutputFormatOptions +import org.veupathdb.lib.cli.diamond.opts.fields.output_format.OutputFormatOptions interface OutputFormatOptionContainer { /** diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/BlastTabFormat.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/BlastTabFormat.kt similarity index 70% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/BlastTabFormat.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/BlastTabFormat.kt index 4b78dfbd..383b9d17 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/BlastTabFormat.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/BlastTabFormat.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format class BlastTabFormat(override var formatFields: Iterable = emptyList()) : BlastTabFormatBase>(OutputFormat.BlastTab) diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/BlastTabFormatBase.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/BlastTabFormatBase.kt similarity index 92% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/BlastTabFormatBase.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/BlastTabFormatBase.kt index 9f1b49f3..f5d86d1b 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/BlastTabFormatBase.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/BlastTabFormatBase.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.annotation.JsonValue import org.veupathdb.lib.jackson.Json diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/FormatField.fn.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/FormatField.fn.kt similarity index 85% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/FormatField.fn.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/FormatField.fn.kt index 073ad3a4..86f7c181 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/FormatField.fn.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/FormatField.fn.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format private var formatFieldCache: Map? = null diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/FormatField.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/FormatField.kt similarity index 99% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/FormatField.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/FormatField.kt index c1754d41..da7e5b4e 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/FormatField.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/FormatField.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/JsonFlatFormat.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/JsonFlatFormat.kt similarity index 70% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/JsonFlatFormat.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/JsonFlatFormat.kt index 3214f0a4..e57d1c00 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/JsonFlatFormat.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/JsonFlatFormat.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format class JsonFlatFormat(override var formatFields: Iterable = emptyList()) : BlastTabFormatBase>(OutputFormat.BlastTab) diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutFormatFormatter.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutFormatFormatter.kt similarity index 90% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutFormatFormatter.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutFormatFormatter.kt index 74ecfb99..c6d19b9b 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutFormatFormatter.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutFormatFormatter.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import io.foxcapades.lib.cli.builder.arg.Argument import io.foxcapades.lib.cli.builder.arg.format.ArgumentFormatter diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormat.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormat.kt similarity index 96% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormat.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormat.kt index a5c2f4d6..609326e9 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormat.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormat.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatDeserializer.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatDeserializer.kt similarity index 87% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatDeserializer.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatDeserializer.kt index 9d8c98cb..3d54d893 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatDeserializer.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatDeserializer.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatOptions.fn.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatOptions.fn.kt similarity index 97% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatOptions.fn.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatOptions.fn.kt index f4465418..07b718b4 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatOptions.fn.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatOptions.fn.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.ArrayNode diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatOptions.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatOptions.kt similarity index 75% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatOptions.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatOptions.kt index cb620c80..fc91b871 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/OutputFormatOptions.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/OutputFormatOptions.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.databind.annotation.JsonDeserialize diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/SimpleOutputFormat.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/SimpleOutputFormat.kt similarity index 97% rename from src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/SimpleOutputFormat.kt rename to src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/SimpleOutputFormat.kt index 90810539..94834c33 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/output_format/SimpleOutputFormat.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/fields/output_format/SimpleOutputFormat.kt @@ -1,4 +1,4 @@ -package org.veupathdb.lib.cli.diamond.opts.output_format +package org.veupathdb.lib.cli.diamond.opts.fields.output_format import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/impl/OutputFormatOptionContainerImpl.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/impl/OutputFormatOptionContainerImpl.kt index c1cc7dcc..d7c568c3 100644 --- a/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/impl/OutputFormatOptionContainerImpl.kt +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/opts/impl/OutputFormatOptionContainerImpl.kt @@ -3,8 +3,8 @@ package org.veupathdb.lib.cli.diamond.opts.impl import io.foxcapades.lib.cli.builder.flag.flag import io.foxcapades.lib.cli.builder.flag.toggleFlag import org.veupathdb.lib.cli.diamond.opts.OutputFormatOptionContainer -import org.veupathdb.lib.cli.diamond.opts.output_format.OutFormatFormatter -import org.veupathdb.lib.cli.diamond.opts.output_format.OutputFormatOptions +import org.veupathdb.lib.cli.diamond.opts.fields.output_format.OutFormatFormatter +import org.veupathdb.lib.cli.diamond.opts.fields.output_format.OutputFormatOptions internal class OutputFormatOptionContainerImpl : OutputFormatOptionContainer { override var outputFormat by flag { formatter = OutFormatFormatter } diff --git a/src/main/kotlin/org/veupathdb/lib/cli/diamond/util/DiamondCommandConfigDeserializer.kt b/src/main/kotlin/org/veupathdb/lib/cli/diamond/util/DiamondCommandConfigDeserializer.kt new file mode 100644 index 00000000..e7d668c4 --- /dev/null +++ b/src/main/kotlin/org/veupathdb/lib/cli/diamond/util/DiamondCommandConfigDeserializer.kt @@ -0,0 +1,31 @@ +package org.veupathdb.lib.cli.diamond.util + +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonDeserializer +import com.fasterxml.jackson.databind.JsonMappingException +import com.fasterxml.jackson.databind.node.ObjectNode +import com.fasterxml.jackson.module.kotlin.contains +import org.veupathdb.lib.cli.diamond.DiamondCommand +import org.veupathdb.lib.cli.diamond.commands.DiamondCommandConfig +import org.veupathdb.lib.cli.diamond.commands.impl.BlastPImpl +import org.veupathdb.lib.cli.diamond.commands.impl.BlastXImpl +import org.veupathdb.lib.jackson.Json + +internal class DiamondCommandConfigDeserializer : JsonDeserializer() { + override fun deserialize(p: JsonParser, ctxt: DeserializationContext): DiamondCommandConfig { + val obj = p.readValueAs(ObjectNode::class.java) + + if ("tool" !in obj) + throw JsonMappingException( + p, + "cannot deserialize given JSON into a DIAMOND command configuration; the given object has no \"tool\" property" + ) + + return when (DiamondCommand.fromJson(obj["tool"])) { + DiamondCommand.BlastP -> Json.parse(obj) + DiamondCommand.BlastX -> Json.parse(obj) + else -> TODO("unsupported type") + } + } +}