With a root command:
new RootCommand
{
new Option<string>("--myoption")
};
how do you tell the difference between
./myapp
and
./myapp --myoption ""
?
I initially assumed that the option would be null if it wasn't specified, but it's not, it's an empty string :( Adding an explicit default of null
also doesn't work; this code still prints out ""
when no options are passed in:
static void Main(string[] args)
{
var rootCommand = new RootCommand
{
new Option<string>("--myoption", () => null)
};
rootCommand.Handler = CommandHandler.Create<string>(Run);
rootCommand.Invoke(args);
}
private static void Run(string myoption)
{
Console.WriteLine(myoption == null ? "(null)" : '"' + myoption + '"');
}
If the default is set to a non-null string, the default does come through as expected; only null
is mysteriously changed into an empty string.