fix: Add choice options to YACL integration
This commit is contained in:
@@ -13,6 +13,7 @@ import moe.nea.firmament.util.ErrorUtil
|
||||
import moe.nea.firmament.util.json.KJsonOps
|
||||
|
||||
class ChoiceHandler<E>(
|
||||
val enumClass: Class<E>,
|
||||
val universe: List<E>,
|
||||
) : ManagedConfig.OptionHandler<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
val codec = StringIdentifiable.createCodec {
|
||||
|
||||
@@ -118,17 +118,17 @@ abstract class ManagedConfig(
|
||||
|
||||
protected fun <E> choice(
|
||||
propertyName: String,
|
||||
universe: List<E>,
|
||||
enumClass: Class<E>,
|
||||
default: () -> E
|
||||
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
return option(propertyName, default, ChoiceHandler(universe))
|
||||
return option(propertyName, default, ChoiceHandler(enumClass, enumClass.enumConstants.toList()))
|
||||
}
|
||||
|
||||
protected inline fun <reified E> choice(
|
||||
propertyName: String,
|
||||
noinline default: () -> E
|
||||
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
return choice(propertyName, enumEntries<E>(), default)
|
||||
return choice(propertyName, E::class.java, default)
|
||||
}
|
||||
|
||||
private fun <E> createStringIdentifiable(x: () -> Array<out E>): Codec<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
|
||||
Reference in New Issue
Block a user