pcimcioch.gitlabci.dsl.job.AfterScriptDsl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gitlab-ci-kotlin-dsl Show documentation
Show all versions of gitlab-ci-kotlin-dsl Show documentation
Library providing Kotlin DSL to configure GitlabCI file
package pcimcioch.gitlabci.dsl.job
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.list
import kotlinx.serialization.builtins.serializer
import pcimcioch.gitlabci.dsl.DslBase
import pcimcioch.gitlabci.dsl.serializer.ValueSerializer
@Serializable(with = AfterScriptDsl.AfterScriptDslSerializer::class)
class AfterScriptDsl : DslBase() {
var commands: MutableList = mutableListOf()
fun exec(command: String) = commands.add(command)
operator fun String.unaryPlus() = [email protected](this)
object AfterScriptDslSerializer : ValueSerializer>(String.serializer().list, AfterScriptDsl::commands)
companion object {
init {
addSerializer(AfterScriptDsl::class, serializer())
}
}
}
fun createAfterScript(block: AfterScriptDsl.() -> Unit = {}) = AfterScriptDsl().apply(block)
fun createAfterScript(vararg elements: String, block: AfterScriptDsl.() -> Unit = {}) = createAfterScript(elements.toList(), block)
fun createAfterScript(elements: Iterable, block: AfterScriptDsl.() -> Unit = {}) = AfterScriptDsl().apply { elements.forEach { exec(it) } }.apply(block)