New issue
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
Options must come before arguments #321
Comments
Can you provide more details on what you mean when you say it doesn't work? Do you have allowInterspersedArgs=false? This command executes like you expect: class Command : CliktCommand() {
private val files by argument().pair()
private val offsets by argument().int().pair()
private val length by argument().int()
private val display by option().switch("-f" to First, "-l" to Largest).default(None)
override fun run() {
echo("$files, $offsets, $length, $display")
}
} Invoking it with |
I have top level command:
I have set |
That top level command looks fine. Can you provide a complete, minimal example that reproduces the issue? I'm having trouble seeing what is causing the problem. |
fun main(args: Array<String>) {
TestCommand().main(args)
}
class TestCommand: NoOpCliktCommand(name = "scanner", allowMultipleSubcommands = true) {
init {
subcommands(Command())
context { allowInterspersedArgs = true }
}
}
class Command: CliktCommand(name = "verify") {
private val files by argument().file().pair()
private val offsets by argument().int().pair()
private val length by argument().int()
private val display by option().switch("-f" to DisplayMatch.First, "-l" to DisplayMatch.Largest).default(DisplayMatch.None)
init { context { allowInterspersedArgs = true } }
override fun run() {
echo("$files $offsets $length $display")
}
}
enum class DisplayMatch {
First, Largest, None
} The Also, thanks for taking your time to take a look at this. EDIT: Just noticed that if I run Command().main(args) and call it with |
Oh, you're using |
I see. But if I set it to false, will that make my current structure not work? the TopLevelCommand with subcommands? |
Give it a try. It will still work. |
Thank you for your help. It currently indeed works without the Thanks you for taking the time to help, appreciate it. |
Am I doing something wrong or do I need to specify options before arguments in command? And if so, is it somewhere in the documentation and I am just blind?
Example code:
The idea is to be able to do
cmd path1 path2 0 0 1024 -f
orcmd path1 path2 0 0 -f
but it doesn't seem to work unless I put the flag in the front:cmd -f path1 path2 0 0 1024
.If this is some limitation of the parser it should be stated clearly in the docs. If this should work, can anyone point me in the right direction?
The text was updated successfully, but these errors were encountered: