下面的简单Program.cs
要求已定义的根命令只有一个参数:
using System.CommandLine;
var inputArgument = new Argument<string>(
name: "--input",
description: "input any value and print it out");
var rootCommand = new RootCommand();
rootCommand.AddArgument(inputArgument);
rootCommand.SetHandler((inputArgumentValue) =>
{
Console.WriteLine($"{inputArgumentValue}");
}, inputArgument);
rootCommand.Invoke(args);
我希望使用以下参数调用它:--input "Hello World"
以在shell 中打印出Hello World.但是,我得到以下错误:
Unrecognized command or argument 'Hello World'.
个
当我将Argument类替换为Option类时,它按预期工作:
using System.CommandLine;
var inputArgument = new Option<string>(
name: "--input",
description: "input any value and print it out");
var rootCommand = new RootCommand();
rootCommand.AddOption(inputArgument);
rootCommand.SetHandler((inputArgumentValue) =>
{
Console.WriteLine($"{inputArgumentValue}");
}, inputArgument);
rootCommand.Invoke(args);
What did I misunderstand about the 100 class? Why can I not pass an argument with a value to it?
由于它的其他属性,我想使用参数类而不是选项.我使用的是.NET 6.0和System.CommandLine版本2.0.0-beta4.22272.1