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

main.de.jensklingenberg.ktorfit.ExampleCommandLineProcessor.kt Maven / Gradle / Ivy

The newest version!
package de.jensklingenberg.ktorfit

import com.google.auto.service.AutoService
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey

@OptIn(ExperimentalCompilerApi::class)
@AutoService(CommandLineProcessor::class) // don't forget!
class ExampleCommandLineProcessor : CommandLineProcessor {
    override val pluginId: String = "ktorfitPlugin"

    override val pluginOptions: Collection =
        listOf(
            CliOption(
                optionName = "enabled",
                valueDescription = "",
                description = "whether to enable the plugin or not",
            ),
            CliOption(
                optionName = "logging",
                valueDescription = "",
                description = "whether to enable logging",
            ),
        )

    override fun processOption(
        option: AbstractCliOption,
        value: String,
        configuration: CompilerConfiguration,
    ) = when (option.optionName) {
        "enabled" -> configuration.put(KEY_ENABLED, value.toBoolean())
        "logging" -> configuration.put(KEY_LOGGING, value.toBoolean())
        else -> configuration.put(KEY_ENABLED, true)
    }
}

val KEY_ENABLED = CompilerConfigurationKey("whether the plugin is enabled")
val KEY_LOGGING = CompilerConfigurationKey("whether logging is enabled")




© 2015 - 2024 Weber Informatics LLC | Privacy Policy