Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Line Parser Library - Boolean Parameter

I try to pass a boolean parameter to a console application and process the value with the Command Line Parser Library.

[Option('c', "closeWindow", Required = true, HelpText = "Close the window.")] public bool CloseWindow { get; set; } 

I tried to pass the parameter as

-c false -c False -c "false" -... 

There are no differences, on each try I get "true" as value.

Can anyone tell me how I have to pass the parameter to get the boolean false value?

To avoid possible asks, there is a string option which is passed correctly:

[Option('s', "system", Required = true, HelpText = "Any help text")] public string System { get; set; } 
like image 868
Sebastian S. Avatar asked Mar 08 '16 17:03

Sebastian S.


2 Answers

You don't need to add True or False. Using -c will evaluate to True. Not using it will evaluate to False. Somewhere in the documentation there is an example with -v for verbose output. But I can't find it right now. I guess Required=true is not necessary for Boolean options.

like image 135
arne.z Avatar answered Oct 01 '22 12:10

arne.z


bool? behaves the way you want

with :

[Option('c', "closeWindow", Required = true, HelpText = "Close the window.")] public bool? CloseWindow { get; set; } 

the result will be :

-c false // -> false -c true  // -> true -c       // -> error          // -> error if Required = true, null otherwise 
like image 31
klev Avatar answered Oct 01 '22 13:10

klev