Improved config DSL
This commit is contained in:
@@ -7,7 +7,7 @@ import com.willfp.eco.core.config.interfaces.Config
|
||||
/**
|
||||
* Helper class to create configs with a kotlin DSL.
|
||||
*/
|
||||
class DSLConfig internal constructor() : BuildableConfig() {
|
||||
class DSLConfig internal constructor(type: ConfigType) : TransientConfig(emptyMap(), type) {
|
||||
infix fun String.to(value: Any?) =
|
||||
set(this, value)
|
||||
}
|
||||
@@ -19,4 +19,26 @@ class DSLConfig internal constructor() : BuildableConfig() {
|
||||
* @return The config.
|
||||
*/
|
||||
fun config(builder: DSLConfig.() -> Unit): Config =
|
||||
DSLConfig().apply(builder)
|
||||
DSLConfig(ConfigType.YAML).apply(builder)
|
||||
|
||||
/**
|
||||
* Helper function to create configs with a kotlin DSL.
|
||||
*
|
||||
* @param type The config type.
|
||||
* @param builder The builder.
|
||||
* @return The config.
|
||||
*/
|
||||
fun config(type: ConfigType, builder: DSLConfig.() -> Unit): Config =
|
||||
DSLConfig(type).apply(builder)
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to create configs with a kotlin DSL.
|
||||
*
|
||||
* Inherits the config type of the sub-builder.
|
||||
*
|
||||
* @param builder The builder.
|
||||
* @return The config.
|
||||
*/
|
||||
fun DSLConfig.config(builder: DSLConfig.() -> Unit): Config =
|
||||
DSLConfig(this.type).apply(builder)
|
||||
Reference in New Issue
Block a user