Rename Label->Version, add version meta field

This commit is contained in:
2026-08-09 20:18:11 +02:00
parent 60b1a69bc6
commit a90b2ebeca
15 changed files with 168 additions and 176 deletions
@@ -98,7 +98,7 @@ object CLI {
sealed interface IProjectIdentification
sealed interface ILabelIdentification
data class ProjectName(val user: String, val project: String) : IProjectIdentification
data class LabelName(val name: String): ILabelIdentification
data class VersionName(val name: String): ILabelIdentification
data class ID(val id: Uuid) : IProjectIdentification, ILabelIdentification
sealed interface IData<T> {
@@ -168,22 +168,23 @@ object CLI {
}
@Suppress("unused")
class AddLabel : CliktCommand(name = "add-label") {
class AddVersion : CliktCommand(name = "add-version") {
val parent by requireObject<Project>()
val name by option("--name", help = "Set the label's name (*)")
val color by option("--color", help = "Set the label's color (*)").check("Color must be specified in RGB-hex-format (#ABCDEF)") {
val name by option("--name", help = "Set the version's name (*)")
val color by option("--color", help = "Set the version's color (*)").check("Color must be specified in RGB-hex-format (#ABCDEF)") {
it.length == 7 && it[0] == '#' && it.substring(1, it.length).all { c -> c.isDigit() || c in "ABCDEF" }
}
val meta by option("--meta", help = "Add metadata to the version (*)")
override fun run() = ProjectHandlers.newLabel(name, color, parent.finder)
override fun run() = ProjectHandlers.newVersion(name, color, parent.finder, meta)
}
@Suppress("unused")
class AddData : CliktCommand(name = "add-data") {
val parent by requireObject<Project>()
val label by mutuallyExclusiveOptions<ILabelIdentification>(
option("--label-id", help = "Set the label by UUID.").convert { ID(Uuid.parse(it)) },
option("--label", help = "Set the label by name.").convert { LabelName(it) }
val version by mutuallyExclusiveOptions<ILabelIdentification>(
option("--version-id", help = "Set the version by UUID.").convert { ID(Uuid.parse(it)) },
option("--version", help = "Set the version by name.").convert { VersionName(it) }
).single()
val warmup by mutuallyExclusiveOptions<IData<Float>>(
option("--warmup", help = "Set warmup data directly.").float().split(",").transformAll { DirectData(it.flatten()) },
@@ -204,7 +205,7 @@ object CLI {
val input by option("--input", help = "Set the input used to benchmark")
val hardware by option("--hardware", "--hw", help = "Set the hardware on which the benchmark was run")
override fun run() = ProjectHandlers.newData(parent.finder, label, warmup, measurement, unit)
override fun run() = ProjectHandlers.newData(parent.finder, version, warmup, measurement, unit, input, hardware)
}
}
}
@@ -1,16 +1,11 @@
package com.jaytux.phoebench.clients.cli
import com.github.ajalt.clikt.parameters.options.convert
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.jaytux.phoebench.clients.cli.CLI.Commands.Project.ProjectName
import com.jaytux.phoebench.common.ApiRoute
import com.jaytux.phoebench.common.Either
import com.jaytux.phoebench.common.EmptyRequest
import com.jaytux.phoebench.common.EntryRequest
import com.jaytux.phoebench.common.ErrorResponse
import com.jaytux.phoebench.common.LabelRequest
import com.jaytux.phoebench.common.LabelResponse
import com.jaytux.phoebench.common.VersionRequest
import com.jaytux.phoebench.common.ProjectRequest
import com.jaytux.phoebench.common.Routes
import com.jaytux.phoebench.common.TimeUnit
@@ -19,9 +14,6 @@ import com.jaytux.phoebench.common.error
import com.jaytux.phoebench.common.fold
import com.jaytux.phoebench.common.map
import com.jaytux.phoebench.common.value
import kotlinx.coroutines.runBlocking
import kotlinx.datetime.toLocalDateTime
import java.nio.file.OpenOption
import kotlin.io.path.Path
import kotlin.io.path.exists
import kotlin.io.path.inputStream
@@ -100,7 +92,7 @@ object ProjectHandlers {
}
}
fun newLabel(name: String?, color: String?, project: CLI.Commands.Project.IProjectIdentification?) {
fun newVersion(name: String?, color: String?, project: CLI.Commands.Project.IProjectIdentification?, version: String?) {
val id = ensureProjectIdentification(project)
val useName = name.maybePrompt("label name") { it }
val useColor = color.maybePrompt("color") {
@@ -111,10 +103,11 @@ object ProjectHandlers {
exitProcess(-1)
}
}
val useVersion = version.maybePrompt("version") { it }
tryAuthenticated {
id.toId().bind { projectId ->
Client.callRoute(Routes.Label.new, LabelRequest(useName, useColor, projectId))
Client.callRoute(Routes.Version.new, VersionRequest(useName, useColor, useVersion, projectId))
}
}.fold({
System.err.println("Could not create label: ${it.msg}")
@@ -139,11 +132,11 @@ object ProjectHandlers {
label: CLI.Commands.Project.ILabelIdentification?,
warmup: CLI.Commands.Project.IData<Float>?,
measurement: CLI.Commands.Project.IData<Float>?,
unit: TimeUnit?
unit: TimeUnit?, input: String?, hardware: String?
) {
val projectId = ensureProjectIdentification(project)
val labelId = label.maybePrompt("label name") {
CLI.Commands.Project.LabelName(it)
val versionId = label.maybePrompt("version name") {
CLI.Commands.Project.VersionName(it)
}
val warmupData = warmup.ensure("warmup").toList()
val measureData = measurement.ensure("measurements").toList()
@@ -162,20 +155,22 @@ object ProjectHandlers {
}
}
}
val useInput = input.maybePrompt("benchmark input") { it }
val useHardware = hardware.maybePrompt("hardware description") { it }
tryAuthenticated {
projectId.toId().bind { pId ->
when(labelId) {
is CLI.Commands.Project.ID -> labelId.id.value()
is CLI.Commands.Project.LabelName -> Client.callRoute(Routes.Project.get, pId).bind {
it.usedLabels.firstOrNull { l -> l.name == labelId.name }?.id?.value()
?: ErrorResponse("Label ${labelId.name} does not exist in this project.").error()
when(versionId) {
is CLI.Commands.Project.ID -> versionId.id.value()
is CLI.Commands.Project.VersionName -> Client.callRoute(Routes.Project.get, pId).bind {
it.usedLabels.firstOrNull { l -> l.name == versionId.name }?.id?.value()
?: ErrorResponse("Label ${versionId.name} does not exist in this project.").error()
}
}.map { pId to it }
}.bind { (pId, lId) ->
}.bind { (pId, vId) ->
Client.callRoute(Routes.Entry.new, EntryRequest(
lId, Clock.System.now(), pId,
warmupData, measureData, timeUnit
vId, Clock.System.now(), pId,
warmupData, measureData, timeUnit, useInput, useHardware
))
}
}