Support for "switch" style arguments
See original GitHub issueForgive me if this is already supported but I couldn’t see how to use it if it is.
I’d like the ability to use options with boolean values that, when specified on the command line, become the opposite of their default values (without specifying a value).
E.g.,
[Option("with-some-feature", Default: false)]
public bool WithSomeFeature { get; set; }
[Option("without-other-feature", Default: true)]
public bool WithoutOtherFeature { get; set; }
$ foo.exe (option WithSomeFeature would be false, WithoutOtherFeature would be true)
$ foo.exe --with-some-feature --without-other-feature (option WithSomeFeature would be true, WithoutOtherFeature would be false)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
pattern matching expressions using the switch keyword
You use the switch expression to evaluate a single expression from a list of candidate expressions based on a pattern match with an...
Read more >switch - JavaScript - MDN Web Docs - Mozilla
The switch statement evaluates an expression, matching the expression's value against a series of case clauses, and executes statements ...
Read more >Switch statement fall-through...should it be allowed? [closed]
I know but switch/case constructs that explicitly use the "case 1: some code case 2: some more code case 3: final code break;"...
Read more >The switch Statement (The Java™ Tutorials > Learning ...
The switch statement evaluates its expression, then executes all statements that follow the matching case label.
Read more >Java Switch Statement
A detailed tutorial about the Switch statement in Java and its ... We compare the switch argument animal with the several case values....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am not conviced the Mutual Exclusive options solve the issue, at least not in a general sense.
I have
some-feature
andother-feature
which are independent, and it makes semantic sense to havesome
default tofalse
andother
default totrue
. Why should the user be forced to either enable one or disable the other, and not both at the same time? How would this scale with more switch-style arguments?This seems like an unnecessary burden derived by adapting mutual exclusive options to an use case they were not designed for.
Mutual Exclusive options can do this out of the box, see this example:
Only, you pass either
--with-some-feature
or--without-other-feature
, not both together.The result of the command:
The result of the command
As you see, they changes values automatic without setting a default value, exclusive to each other. Note: Mutually exclusive options need to have a different
SetName
.Try online Demo