clikt icon indicating copy to clipboard operation
clikt copied to clipboard

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

Open alegomes opened this issue 10 months ago • 5 comments

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

If not, what's the best alternative?

thanks

alegomes avatar Apr 02 '24 12:04 alegomes

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.

ajalt avatar Apr 02 '24 16:04 ajalt

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?

alegomes avatar Apr 02 '24 17:04 alegomes

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

ajalt avatar Apr 02 '24 18:04 ajalt

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 (…) ?

alegomes avatar Apr 02 '24 20:04 alegomes

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.

ajalt avatar Apr 02 '24 21:04 ajalt