commandlineparser / commandlineparser/commandline

ParseArguments<T> with only a single TOptions doesnt respect Verb attribute

Offen
#384 3 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

When MapResults is presented with only a single Verb-style Options class, the verb is not properly popped off the args stack.

Following code doesnt parse commandline `"myprogram pack MyProjectfile.csproj"`. You end up with `PackOptions.ProjectFile == "pack"` Works fine if additional Options classes with `VerbAttribute` specified.

```c#
public static class Program
{
public static void Main(string[] args)
{
int exitcode = CommandLine.Parser.Default
.ParseArguments(args)
.MapResult(
(PackOptions opts) => 0, //basically do nothing for sample
(parserErrors) => 1
);
}
}

[Verb("pack")]
public class PackOptions
{
[Value(0)]
public string ProjectFile { get; set; }

[Option("outputPath")]
public string OutputPath { get; set; }
}
```

created a dotnetfiddle: https://dotnetfiddle.net/IbwLbX

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.