Open
Description
I created a small and simple snipped for demonstrating the issue
static int Main(string[] args)
{
// Create a root command with some options
var rootCommand = new RootCommand
{
new Option<string>(
new [] { "--CssFile", "-css"},
getDefaultValue: () => "42",
description: "An option whose argument is parsed as a string"),
new Option<string>(
new [] {"--CollectionUri", "--Collection", "-c"},
getDefaultValue: () => "82",
"An option whose argument is parsed as a string"),
};
rootCommand.Description = "My sample app";
// Note that the parameters of the handler method are matched according to the names of the options
rootCommand.Handler = CommandHandler.Create<string, string>((cssFile, collectionUri) =>
{
Console.WriteLine($"The value for --CssFile is: {cssFile}");
Console.WriteLine($"The value for --Collection is: {collectionUri}");
});
// Parse the incoming args and invoke the handler
return rootCommand.InvokeAsync(args).Result;
}
checking the usage looks just fine
ConsoleApp.CommandLine:
My sample app
Usage:
ConsoleApp.CommandLine [options]
Options:
-css, --CssFile <CssFile> An option whose argument is parsed as an int [default: 42]
-c, --Collection, --CollectionUri <CollectionUri> An option whose argument is parsed as a int [default: 82]
--version Show version information
-?, -h, --help Show help and usage information
running with these Arguments
--CssFile "Default.css" --Collection "https://example.org/segment"
or
--CssFile "Default.css" -c "https://example.org/segment"
produces the expected result
The value for --CssFile is: Default.css
The value for --Collection is: https://example.org/segment
running with Arguments
-css "Default.css" -c "https://example.org/segment"
or
-css "Default.css" --Collection "https://example.org/segment"
produces
Option '-c' expects a single argument but 2 were provided.
Option '-c' expects a single argument but 2 were provided.
Unrecognized command or argument 'Default.css'
am I doing something wrong?