commandlineparser / commandlineparser/commandline

Invalid verbs do not cause errors if a default verb is set

未关闭
#849 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

Below is a very simplified C# console application I called DefaultVerb. Running the application with **start** or **finish** works as expected, outputting Start or Finish correctly, but if I run the application with **DefaultVerb.exe foo**, it outputs Start. If I set isDefault to false, and run **DefaultVerb.exe foo** I receive the following expected error:
`ERROR(S):
Verb 'foo' is not recognized.
--help Display this help screen.
--version Display version information.
`
When I have isDefault: true on my verb, what should be the behavior if I pass in an invalid verb? I'm not expecting a bad verb to run my default verb.

`
using CommandLine;
using System;

internal class Program
{
[Verb("start", isDefault: true, HelpText = "start help")]
class StartOptions
{
}

[Verb("finish", HelpText = "finish help")]
class FinishOptions
{
}

static void Main(string[] args)
{
var parser = new Parser(settings =>
{
settings.AutoVersion = false;
settings.CaseSensitive = false;
settings.HelpWriter = Console.Out;
});

parser.ParseArguments(args)
.WithNotParsed(ExitWithError)
.WithParsed(DoSomething);
}

static void DoSomething(object commandObj)
{
switch (commandObj)
{
case StartOptions:
Console.WriteLine("Start");
break;
case FinishOptions:
Console.WriteLine("Finish");
break;
}
}
static void ExitWithError(IEnumerable errors)
{
Environment.Exit(1);
}
}
`

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。