Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi instance setting ignored when default verb is parsed. #922

Open
federico-soberanes opened this issue Mar 18, 2024 · 0 comments
Open

Comments

@federico-soberanes
Copy link

Describe the bug
When using the function "MapResult" to parse multiple verbs, the parser ignores the setting "AllowMultiInstance" while parsing the default verb.

Lib version: 2.9.1
Language: C#

To Reproduce
Test the following demo code to see the result.

Demo Class Options:

    [Verb("log", isDefault:true, HelpText = "Log command")]
    class LogOptions
    {
        [Option('a', HelpText = "Option A for log command")]
        public IEnumerable<string> OptionA { get; set; }

        [Option('b', HelpText = "Option B for log command")]
        public IEnumerable<string> OptionB { get; set; }
    }

    [Verb("save", HelpText = "Save command")]
    class SaveOptions
    {
        [Option('d', HelpText = "Option D for save command")]
        public IEnumerable<string> OptionD { get; set; }

        [Option('e', HelpText = "Option E for save command")]
        public IEnumerable<string> OptionE { get; set; }
    }

Demo code:

        Parser parser = new(x =>
        {
            x.HelpWriter = Console.Out;
            x.IgnoreUnknownArguments = true;
            x.AllowMultiInstance = true;
            x.AutoHelp = true;
        });

        var argTest1 = "log -a valueA -b valueB" .Split(' ');  // This works.
        var argTest2 = "save -d valueD -e valueE".Split(' ');  // This works.
        var argTest3 = "-a valueA -b valueB".Split(' ');       // This works.
        var argTest4 = "log -a valueA -b valueB -b valueB2".Split(' '); // This works.
        var argTest5 = " -a valueA -b valueB -b valueB2".Split(' ');     // This don't work.


        var res = parser.ParseArguments<LogOptions, SaveOptions>(argTest5).MapResult(
        (LogOptions opts) => ProcessLogCommand(opts),
        (SaveOptions opts) => ProcessSaveCommand(opts),
        errs => 1);
    }

When trying to parse argTest5 this error is shown:

  ERROR(S):
    Option 'b' is defined multiple times.
  
    -a           Option A for log command
  
    -b           Option B for log command
  
    --help       Display this help screen.
  
    --version    Display version information.

Expected behavior
Option "SaveOptions" correctly parsed with multiple arguments for argument b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant