Skip to content

Passing "0" to boolean option results in "true" value #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ericnewton76 opened this issue Nov 4, 2017 · 2 comments
Closed

Passing "0" to boolean option results in "true" value #89

ericnewton76 opened this issue Nov 4, 2017 · 2 comments

Comments

@ericnewton76
Copy link
Member

Issue by ptylenda
Tuesday Sep 20, 2016 at 11:47 GMT
Originally opened as gsscoder/commandline#354


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

@ericnewton76
Copy link
Member Author

Comment by anthonylangsworth
Saturday Oct 22, 2016 at 12:01 GMT


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.

@ericnewton76
Copy link
Member Author

Comment by Agbar
Wednesday Jan 04, 2017 at 20:13 GMT


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants