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 for "switch" style arguments

See original GitHub issue

Forgive 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
rzippocommented, Feb 5, 2020

I am not conviced the Mutual Exclusive options solve the issue, at least not in a general sense.

Only, you pass either --with-some-feature or --without-other-feature, not both together.

I have some-feature and other-feature which are independent, and it makes semantic sense to have some default to false and other default to true. 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.

1reaction
moh-hassancommented, Mar 31, 2019

Mutual Exclusive options can do this out of the box, see this example:

      class  Options
	{
		[Option("with-some-feature", SetName = "enable")]
	  public  bool WithSomeFeature { get; set; }

		[Option("without-other-feature", SetName = "disable")]
	 public   bool  WithoutOtherFeature { get; set; }
	}

Only, you pass either --with-some-feature or --without-other-feature , not both together.

The result of the command:

	--with-some-feature

	WithSomeFeature = True
	WithoutOtherFeature = False

The result of the command

	--without-other-feature

	WithSomeFeature = False
	WithoutOtherFeature = True

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

Read more comments on GitHub >

github_iconTop 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 >

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