ajalt / clikt

Multiplatform command line interface parsing for Kotlin
https://ajalt.github.io/clikt/
Apache License 2.0
2.51k stars 121 forks source link

Question: by option().multiple().groupChoice() ? #505

Open alegomes opened 5 months ago

alegomes commented 5 months ago

Can I use multiple() and choiceGroup() in the same option?

If not, what's the best alternative?

thanks

ajalt commented 5 months ago

No, I'm not sure how that would work. Options aren't ordered, so if you called the group option more than once, how would we know which instance of the group each option on the command line belongs to?

It sounds like subcommands would work better than groups here; you can repeat subccommands.

alegomes commented 5 months ago

This is what I tought:

myCmd --groupedOpt=valueA --valueAargs1=x --valueAargs2=y --groupedOpt=valueB --valueBargs1=z

Which is the same groupChoice multiple times but with different values.

Does it make sense?

ajalt commented 5 months ago

The problem is that options aren't ordered, so trying to parse repeated groups would be ambiguous:

myCmd --valueAargs1=x --valueAargs2=y --groupedOpt=valueA --valueAargs2=z --groupedOpt=valueA --valueAargs2=a
alegomes commented 5 months ago

The problem is that options aren't ordered, so trying to parse repeated groups would be ambiguous:

myCmd --valueAargs1=x --valueAargs2=y --groupedOpt=valueA --valueAargs2=z --groupedOpt=valueA --valueAargs2=a

Even if you define all sub-options values as unique? i.e. valueAargs1 ≠ valueAargs2 ≠ valueBargs1 (…) ?

ajalt commented 5 months ago

Yes. multiple would mean that a group can be specified more than once, so there's no way to know which instance of a given group any invocation of one of its options should belong to.

But if you have two groups and want them both used at once, why bother with groupChoice? You can just make them separate top level groups.