Description
In the example bellow I was expecting that running cli
without specifying a subcommand would fail with the error "Required command was not provided." as it happens without using the host
var root = new Command("cli")
{
Subcommands = { new Command("cmd") }
};
var configuration = new CommandLineConfiguration(root).UseHost(
_ => Host.CreateDefaultBuilder(),
cfg => cfg.UseInvocationLifetime());
await configuration.InvokeAsync(args);
However, it works fine and no errors pop up. It seems that UseHost
calls HostingAction.SetHandlers
extensions on the root command and it sets actions to all commands in the chain. As a result, this validation never sets the error.
command-line-api/src/System.CommandLine/Parsing/CommandResult.cs
Lines 46 to 55 in b7f0d1c
Was it made intentionally? As a workaround I can use Validators and check that there are tokens provided in the arguments list, but it would be nice to keep the same behaviour as it works without using a host.