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

Nullable boolean Options aren't supported #530

Open
goncalo-oliveira opened this issue Mar 1, 2023 · 1 comment
Open

Nullable boolean Options aren't supported #530

goncalo-oliveira opened this issue Mar 1, 2023 · 1 comment
Labels

Comments

@goncalo-oliveira
Copy link

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

@natemcmaster
Copy link
Owner

Did you try this instead?

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

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

No branches or pull requests

2 participants