commandlineparser / commandlineparser/commandline

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

Abierto
#849 1 comentario 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
C#
Estrellas
4.8k
Forks
478
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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);
}
}
`

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza con la llamada a Parser.ParseArguments mostrada en el issue y reproduce el comportamiento usando DefaultVerb.exe foo con el verbo predeterminado habilitado. Traza cómo se gestiona un verbo no reconocido cuando existe un verbo predeterminado y, después, verifica que la entrada no válida llegue a la ruta de error en lugar de a DoSomething o al verbo predeterminado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp
Área
cli
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.