Skip to content
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

A boolean property parsed incorrectly #940

Open
svonidze opened this issue Dec 14, 2024 · 1 comment
Open

A boolean property parsed incorrectly #940

svonidze opened this issue Dec 14, 2024 · 1 comment

Comments

@svonidze
Copy link

Describe the bug
A boolean property parsed incorrectly, at the same time nullable boolean property - ok!

To Reproduce
https://dotnetfiddle.net/fwRMdJ

class Options
{
    [Option('a', "option1", Required = true)]
    public bool Option1 { get; set; }

    [Option('b', "option2", Required = false)]
    public bool? Option2 { get; set; }
}

class Program
{
    static int Main(string[] args)
    {
      args = "--option1 false --option2 false".Split(' ');
		
        return Parser.Default.ParseArguments<Options>(args)
        .MapResult(
          options => RunAndReturnExitCode(options),
          _ => -1);
    }

    static int RunAndReturnExitCode(Options options)
    {
        Console.WriteLine($"option1={options.Option1}, option2={options.Option2}");
        return 0;
    }
}

option1=True, option2=False

Expected behavior
option1=False, option2=False

@DrusTheAxe
Copy link

DrusTheAxe commented Dec 19, 2024

Same root problem as I'm having?

#783 (comment)

You have a boolean option default=true. Does CommandLineParser not support setting booleans to false?

If you change option2 to default = true and run with --option2 false do you still get the same result?

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