Have you considered exposing the parsing aspects o...
# clikt
r
Have you considered exposing the parsing aspects of clikt without the command aspects? Mostly what I really want is to turn the args into an instance of a data class, and clikt’s parsing is brilliant, but it’s a bit cumbersome to avoid the command aspect.
I’ve done it before like this:
Copy code
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required

data class Config(val username: String)

class CliParser private constructor() : NoOpCliktCommand(
  name = "",
  help = "help text",
) {

  private val username: String by option(help = "the username").required()

  private fun toConfig() = Config(username = username)

  companion object {

    fun parseConfig(vararg args: String): Config =
      CliParser()
        .apply { parse(args.toList()) }
        .toConfig()
  }
}