【发布时间】:2021-02-03 21:24:02
【问题描述】:
我正在尝试使用 System.CommandLine,但我无法让我的处理程序查看我传入的任何值。我尝试了最简单的命令行程序来查看是否有任何值成功了,到目前为止我还没有成功。我的目标是 .NET 4.7.2,我正在使用 System.CommandLine 2.0.0-beta1.20574.7
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
static class Program
{
public static void Main(string[] args)
{
var rootCommand = new RootCommand
{
new Option("--continue", "continue option")
};
rootCommand.Description = "Testing System.CommandLine";
rootCommand.Handler = CommandHandler.Create<bool>
((willContinue) => run(willContinue));
rootCommand.Invoke(args);
}
private static void run(bool willContinue)
{
Console.WriteLine(willContinue);
}
}
无论我如何称呼我的应用程序,我都没有看到 willContinue 的价值是真实的。
myapp.exe --continue -> False
myapp.exe --cont -> Unrecognized command or argument '--cont'(我的选择至少得到认可)
myapp.exe --continue true -> Unrecognized command or argument 'true'
myapp.exe --help->
我的应用程序:
测试 System.CommandLine用法:
myapp [选项]选项:
--continue 继续选项
--version 显示版本信息
-?, -h, --help 显示帮助和使用信息
【问题讨论】:
标签: c# system.commandline