4
Vote

bool parsing issue

description

Hello,


The Command Line Parser is a great library to use for parsing arguments but it does have one problem that i find annoying. Let's say that I have an options class with a bool property. The corresponding argument that will be parsed will be the string "False". The ParseArguments method won't return false, so I understand that the parsing has succeeded. When I check the bool property of the options object it returns true. If i pass the string "false" as an argument the property will be false after the parsing. I don't find this to be the correct way the parser should function. When I compose an array of arguments I will be tempted to use the bool.FalseString constant which is in fact the "False" string.
I am curious why the ParseArguments doesn't return false if for a bool option the argument value is "False". If that's the normal behavior for the ParseArguments method I don't think it would be too much to ask to correctly parse the bool.FalseString and bool.TrueString values when they are passed as arguments.


Thank you for your consideration.

comments

rokxer wrote Oct 15, 2013 at 1:49 PM

Bool options are true if they are present and false if they are not.

text.exe -c Option for c returns true.
text.exe Option for c return false.

TheMuffinMan wrote Sep 19, 2014 at 2:55 AM

Good to know, but honestly and respectfully that functionality is ridiculous.

The Options attribute lets you specify a default value. So on a boolean you shoot yourself in the foot. It can never be false!

wrote Dec 9, 2014 at 4:44 PM

mbergin wrote Dec 9, 2014 at 4:48 PM

At least disallow DefaultValue = true on bool options, because there is no way to set the value to false from the command line in this case.

wrote Jan 5, 2015 at 9:00 PM

treehan77 wrote Jan 5, 2015 at 9:01 PM

Why would i need a default value or Required value if its always false if its an argument? Allow it to accept true or false, duh!

jgisana wrote Mar 22, 2015 at 11:28 PM

I have an existing application that does not have a command line parameter for say LogErrors but defaults it in the code to true. I would like to add a command line parameter say -e that defaults it to true so that I don't break existing scripts. A new script needs to set this to false. This does not seem to be possible with your implementation.

raluru wrote Apr 16, 2015 at 12:03 PM

First of all, thanks for this nice library. It has an elegant API. However, I have an issue with bool options. My application has a default value of true for one of the options and if the user doesn't want it to be true, they should set it to false. This behaviour is not possible with your current version of the library. My workaround is to use string and write extra help text and take extra care while using the option!

It would be neat and user-friendly to be able to specify arguments like this:

MyTestApp.exe --startHub true --startNode false
MyTestApp.exe --startHub true --startNode true which is equivalent to MyTestApp.exe (because default is true for both)
MyTestApp.exe --startHub false
etc.

I hope this helps clarify some of the comments above. This behaviour will make the elegant API nice to use also.

wrote Apr 22, 2015 at 5:26 PM