0

I'd like to use Clikt to parse database search arguments from a TextField in a Compose Desktop app, but in the documentation all the examples seem to include the run function like this:

class Filter : CliktCommand() {    
    val firstName: String? by option()
    val timeframe: String? by option().choice("any", "today", "week")
    override fun run() = Unit
}

Is there a way to just parse a string and get the resulting options so that I can use them for other purposes without running the command itself? I'm thinking about something like this (pseudocode):

val filter = CliktEtc.parse(argv).as(Filter::class)

1 Answer 1

0

I've figured it out. There's a parse method that populates the properties:

val argv = Commandline.translateCommandline("--first-name bob --timeframe today")
val result = Filter().apply { parse(argv) }

Since I'm using a plain string for it I also need something to parse that string, but unfortunatelly neither Clikt nor picocli support plain strings (only arrays) so I added the org.apache.ant as a dependency. That's where the Commandline from this answer comes from.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.