question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support different types for mutuallyExclusiveOptions?

See original GitHub issue

Sometimes it’s useful if mutually exclusive options could be of different types. In my concrete case, an option is either a path to a File, or a String name of a resource. Currently, that’s not supported as all mutually exclusive options need to be of the same type.

I tried to work around that by also treating the File as a String, but I did not find an elegant way then to determine which of the two options was given and whether I should convert the String to a File or not.

I acknowledge it’s not possible to support different types for all mutually exclusive options, but maybe as a work-around we could at least support two different types for the first two mandatory option1 and options2 parameters of mutuallyExclusiveOptions?

In any case I’m also open to other suggestion how to elegantly tackle this issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ajaltcommented, Jan 24, 2020

If you just want Any, then you can cast each option:

val opt by mutuallyExclusiveOptions(
        option("-x").file() as OptionDelegate<Any?>,
        option("-y") as OptionDelegate<Any?>
)

I’m not sure why the type inference can’t figure out the types without a manual cast.

0reactions
sschuberthcommented, Jan 24, 2020

My fault, I forgot to call .single() 🙄 Looking all good now, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support for mutual exclusive options · Issue #199 - GitHub
A first cut of support for ArgGroup s has landed in master. This adds support for: mutually exclusive options and positional parameters ......
Read more >
Mutually Exclusive: What It Means, With Examples
Mutually exclusive events are events that can't both happen, but should not be considered independent events. Independent events have no impact on the...
Read more >
Mutually Exclusive & Collectively Exhaustive Categories - Cvent
First, the categories (response options) must be mutually exclusive, which means they do not overlap with one another.
Read more >
Does Typescript support mutually exclusive types?
I would like Typescript to verify that the object being passed in (at typescript compile-time, I understand run-time is a different animal) only...
Read more >
Mutually Exclusive Events - Math is Fun
Turning left and scratching your head can happen at the same time; Kings and Hearts, because we can have a King of Hearts!...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found