commandlineparser / commandlineparser/commandline

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

Aperta
#384 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
4.8k
Fork
478
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.