Skip to content

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

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

Open
ptylenda opened this issue Sep 20, 2016 · 2 comments
Open

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

ptylenda opened this issue Sep 20, 2016 · 2 comments

Comments

@ptylenda
Copy link

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

@anthonylangsworth
Copy link
Contributor

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.

@Agbar
Copy link

Agbar commented Jan 4, 2017

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

3 participants