CommandLineUtils
CommandLineUtils copied to clipboard
Nullable boolean Options aren't supported
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
Did you try this instead? https://github.com/natemcmaster/CommandLineUtils/blob/81199c7ec68367ea9612be55719dc1fe08f658da/docs/docs/options.md?plain=1#L73-L76
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.
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.