We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions import com.github.ajalt.clikt.parameters.groups.single import com.github.ajalt.clikt.parameters.options.convert import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.option sealed class RunMode01 { data class Server(val isS: Boolean) : RunMode01() data class Client(val address: String) : RunMode01() } class Config01 : CliktCommand() { private val runMode: RunMode01? by mutuallyExclusiveOptions( option("-s", "--server").flag().convert { RunMode01.Server(it) }, option("-c", "--client").convert { RunMode01.Client(it) } ).single() override fun run() = echo(runMode) } sealed class RunMode02 { data class Server(val isS: String) : RunMode02() data class Client(val address: String) : RunMode02() } class Config02 : CliktCommand() { private val runMode: RunMode02? by mutuallyExclusiveOptions( option("-s", "--server").convert { RunMode02.Server(it) }, option("-c", "--client").convert { RunMode02.Client(it) } ).single() override fun run() = echo(runMode) } fun main(args: Array<String>) { val config01 = Config01() print("case 01: =>") config01.main(arrayOf("-s")) // print("case 02: =>") // config01.main(arrayOf("-c", "aaa")) // error val config02 = Config02() print("case 03: =>") config02.main(arrayOf("-s", "bbb")) print("case 04: =>") config02.main(arrayOf("-c", "ccc")) }
case 01: =>Server(isS=true) case 02: =>Usage: config01 [OPTIONS]
Error: option --server cannot be used with --client
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
case 01: =>Server(isS=true)
case 02: =>Usage: config01 [OPTIONS]
Error: option --server cannot be used with --client
The text was updated successfully, but these errors were encountered: