commandlineparser / commandlineparser/commandline

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

Ouverte
#849 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
C#
Étoiles
4.8k
Forks
478
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par l’appel à Parser.ParseArguments montré dans l’issue et reproduisez le comportement en utilisant DefaultVerb.exe foo avec le verbe par défaut activé. Suivez le traitement d’un verbe non reconnu lorsqu’un verbe par défaut existe, puis vérifiez que l’entrée invalide atteint le chemin d’erreur plutôt que DoSomething ou le verbe par défaut.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
csharp
Domaine
cli
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.