commandline
commandline copied to clipboard
Passing "0" to boolean option results in "true" value
Define option:
[Option('e', "engineering", SetName = "console", Required = false, HelpText = "Flag whether the build is engineering build")]
public bool Engineering { get; set; }
When passing "-e 0" to the executable, it results in boolean "true" value, which is unexpected. In conjunction with #353 it results in no possibility to have command line option which would accept 1/0/true/false and work correctly
Unfortunately, this appears to be by design, @ptylenda . Take the following example:
[Option('e', "engineering")]
public bool Engineering { get; set; }
[Value(0)]
public int Count { get; set; }
How would the library parse the arguments -e 0
? The current master branch sets Engineering
to true
and Count
to 0
. Adding the your suggestion would either make the arguments ambiguous or break compatibility with the previous argument parsing result.
Please let me know if I misinterpreted your suggestion.
Grammar Details article on wiki explains why it doesn't work as you would expect.
Boolean properties are flags which means value is set (to true
) when flag is in command line. -e 0
maps to Engineering
set to true and unbound value 0
.
If you really need passing true/false/1/0
arguments you can use enum
like shown in CommandLine.Demo project and mentioned in Mapping Properties to Options:
enum BooleanValue {false, true}
//...
[Option('e')]
public BooleanValue Engineering { get; set; }
You can use then both -e true
or -e 1
in command line.
IMO this issue can be rejected.
EDIT: Of course my remarks apply to version 1.9 while this issue seems to regard upcoming v2.