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

Created on 23 Dec 2018  路  3Comments  路  Source: commandlineparser/commandline

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

Most helpful comment

I also stumbled on the issue (as I only have 1 verb currently) and worked around the issue by passing object as second verb type - this forces the library to use the correct extension method:

            return Parser.Default
                .ParseArguments<ExportOptions, object>(args)
                .MapResult(
                    (ExportOptions opts) => 0,
                    errs => 1);

All 3 comments

Duplicate of #65

I also stumbled on the issue (as I only have 1 verb currently) and worked around the issue by passing object as second verb type - this forces the library to use the correct extension method:

            return Parser.Default
                .ParseArguments<ExportOptions, object>(args)
                .MapResult(
                    (ExportOptions opts) => 0,
                    errs => 1);

@kvalev ,Good Trick
@ericnewton76 ,I modified your demo using object as second verb type and give the same result.
Modified demo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moh-hassan picture moh-hassan  路  3Comments

IB38 picture IB38  路  4Comments

Rohansi picture Rohansi  路  6Comments

TheNybbler picture TheNybbler  路  3Comments

ppumkin picture ppumkin  路  4Comments