isXander / isXander/YetAnotherConfigLib

Add kotlin DSL for list options

Open
#196 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
155
Forks
68
PR merge metrics
No merged PRs in 30d

Description

Currently, there is no kotlin DSL for list options.

Here is a very quick implementation I made of that (in my implementation I had to use reflection to grab the groupKey, but that's only bc I don't have access to your private api)


// OptionRegistrar (API.kt)
interface OptionRegistrar {
    fun <T> registerList(id: String, @BuilderInference block: ListOptionDsl<T>.() -> Unit): ListOption<T>

    fun <T> registeringList(id: String? = null, @BuilderInference block: ListOptionDsl<T>.() -> Unit): RegisterableActionDelegateProvider<ListOptionDsl<T>, ListOption<T>>
}

// API.kt
interface ListOptionDsl<T> : ListOption.Builder<T>, Buildable<ListOption<T>> {
    val optionKey: String
    val optionId: String
    val thisOption: CompletableFuture<ListOption<T>>

    fun OptionDescription.Builder.addDefaultText(lines: Int? = null) = addDefaultText("$optionKey.description", lines)
}

// OptionRegistrarImpl (Impl.kt)
class OptionRegistratImpl {
    override fun <T> registerList(id: String, @BuilderInference block: ListOptionDsl<T>.() -> Unit) = register(id, ListOptionDslImpl<T>(id, groupKey).apply(block).build())

    override fun <T> registeringList(id: String? = null, @BuilderInference block: ListOptionDsl<T>.() -> Unit) = RegisterableActionDelegateProvider(this::registerList, block, id)
}

// Impl.kt
class ListOptionDslImpl<T>(
    override val optionId: String,
    groupKey: String,
    private val builder: ListOption.Builder<T> = ListOption.createBuilder(),
) : ListOptionDsl<T>, ListOption.Builder<T> by builder {
    override val optionKey = "$groupKey.option.$optionId"

    override val thisOption = CompletableFuture<ListOption<T>>()
    override val built = thisOption

    init {
        builder.name(Text.translatable(optionKey))
    }

    override fun OptionDescription.Builder.addDefaultText(lines: Int?) = addDefaultText(prefix = "$optionKey.description", lines = lines)

    override fun build(): ListOption<T> = builder.build().also { thisOption.complete(it) }
}

// Extensions.kt
fun <T : Any> ListOption.Builder<T>.binding(property: KMutableProperty0<List<T>>, default: List<T>) {
    binding(default, { property.get() }, { property.set(it) })
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the OptionRegistrar declarations in API.kt, their implementation in Impl.kt, and the builder extensions in Extensions.kt. Compare the proposed list-option DSL with the existing option builder APIs, then verify that list options can be registered, built, and bound through the new DSL; the issue does not name a test file.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.