CommandLineUtils icon indicating copy to clipboard operation
CommandLineUtils copied to clipboard

Nullable boolean Options aren't supported

Open goncalo-oliveira opened this issue 1 year ago • 1 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

goncalo-oliveira avatar Mar 01 '23 16:03 goncalo-oliveira

Did you try this instead? https://github.com/natemcmaster/CommandLineUtils/blob/81199c7ec68367ea9612be55719dc1fe08f658da/docs/docs/options.md?plain=1#L73-L76

natemcmaster avatar Jun 25 '23 09:06 natemcmaster

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

github-actions[bot] avatar Jun 25 '24 01:06 github-actions[bot]

Closing due to inactivity. If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.

github-actions[bot] avatar Jul 09 '24 01:07 github-actions[bot]