commandlineparser / commandline

The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support
MIT License
4.46k stars 473 forks source link

Parsing FlagCounter argument fails with `isDefault` Verb #888

Open wondras4 opened 1 year ago

wondras4 commented 1 year ago

Parsing FlagCounter arguments fail, when used together with default Verb feature with following error

ERROR(S):
  Option 'v' is defined multiple times.

code sample:

[Verb("option", isDefault: true)]
class Options
{
    [Option('v', FlagCounter = true)]
    public int Verbose { get; set; }
}

class Program
{
    static int Main(string[] args)
    {
        args = "-vv".Split(' ');
        var parser = new Parser(opts => { opts.GetoptMode = true; });
        var parsed = parser.ParseArguments<Options, object>(args);

        Console.WriteLine(parsed.Value == null ? "Parsing failed" : "Flag parsed");     
        return 0;
    }
}

When either specifying Verb explicitly (args = "option -vv"), or when counter value is <= 1 (args = "-v") or when not using Verbs parsing parser.ParseArguments<Options>(args), the sample above completes and successfully parses the flag value.