All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.EnvRaptorSettingValueProvider.kt Maven / Gradle / Ivy

There is a newer version: 0.27.0
Show newest version
package io.fluidsonic.raptor

import io.github.cdimascio.dotenv.*

// TODO Rework this & support multiplatform.
private val dotenv = dotenv { ignoreIfMissing = true }


private class EnvRaptorSettingValueProvider(
	private val name: String,
	default: String?,
) : RaptorSettings.ValueProvider {

	init {
		require(name.isNotBlank()) { "Name of environment variable cannot be blank." }
	}

	override val value = dotenv[name] ?: default


	override val description: String
		get() = "environment variable '$name'"
}


public fun RaptorSettings.ValueProvider.Companion.env(name: String, default: String? = null): RaptorSettings.ValueProvider =
	EnvRaptorSettingValueProvider(name = name, default = default)


@RaptorDsl
@Suppress("UnusedReceiverParameter")
public fun RaptorSettings.Builder.env(name: String, default: String? = null): RaptorSettings.ValueProvider =
	RaptorSettings.ValueProvider.env(name = name, default = default)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy