natemcmaster / CommandLineUtils

Command line parsing and utilities for .NET

Home Page:https://natemcmaster.github.io/CommandLineUtils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nullable boolean Options aren't supported

goncalo-oliveira opened this issue · comments

Describe the bug

When using a nullable boolean with an option of type CommandOptionType.SingleOrNoValue, the argument value isn't binded. It only works if the property isn't nullable.

To Reproduce

Using version 4.0.2 of the library. To reproduce, add a property with a nullable boolean

public class InstallCommand
{
    [Option( "--install-proxy", CommandOptionType.SingleOrNoValue )]
    public bool? InstallProxy { get; set; }

    protected Task<int> OnExecute( CommandLineApplication app )
    {
        Console.WriteLine( $"install proxy: {InstallProxy}" );

        return Task.FromResult( 0 );
    }
}

Execute with the argument --install-proxy or --install-proxy=true or --install-proxy=false.

The InstallProperty value will still be set to null.

The output

$ dotnet run -- install --install-proxy
install proxy: 

Expected behavior

I would expect the argument value to be binded to the property value.

Screenshots

image

Did you try this instead?

[Option]
public (bool hasValue, string value) LogLevel { get; set; }
// Inferred type = SingleOrNoValue
// Inferred names = "-l", "--log-level"