commandlineparser / commandlineparser/commandline
Invalid verbs do not cause errors if a default verb is set
- Linguagem predominante
- C#
- Estrelas
- 4.8k
- Forks
- 478
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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);
}
}
`
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Start with the Parser.ParseArguments call shown in the issue and reproduce the behavior using DefaultVerb.exe foo with the default verb enabled. Trace how an unrecognized verb is handled when a default exists, then verify that the invalid input reaches the error path rather than DoSomething or the default verb.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- csharp
- Domínio
- cli
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100