commandlineparser / commandlineparser/commandline

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

Open
#384 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.8k
Forks
478
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.