commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Issue with boolean switch after verb

Open giovani-luigi opened this issue 4 years ago • 5 comments

Issue When using a boolean switch after a verb, I cannot set it to false

Example: app.exe install --feature=false

Options class

[Verb("install", HelpText = "Install something")]
class Options
{
        [Option('f', "feature", Required = false, Default = true, HelpText = "Enable a feature")]
        public bool EnableFeature { get; set; }
}

Expected: Feature = False

Actual result: Feature = True

Demo code: https://dotnetfiddle.net/lSBqxp

Edit1 Add Options class code

giovani-luigi avatar Oct 06 '21 22:10 giovani-luigi

I've met the same issue, whatever you input, the result for the bool option is always true. It's so mess.

greatkeke avatar Oct 13 '21 09:10 greatkeke

I've also had the same problem.
PS This project is a neat way to add commandline options to your app. Thanks 👍

DavidWiseman avatar Nov 10 '21 20:11 DavidWiseman

I found here that you can workaround it if you make bools nullable, i.e. bool? instead of bool.

It's weird and unexpected, and clearly a recurring issue. It should at least throw an error if I do --xxx=false on a non-nullable boolean.

2bam avatar Nov 28 '21 15:11 2bam

I'm having the same issue

olfek avatar Dec 30 '21 21:12 olfek

Related to #702

olfek avatar Dec 31 '21 06:12 olfek