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

Error parsing with IgnoreUnknownArguments to true and IEnumerable<int> option #835

Open
alvarodl opened this issue Jul 13, 2022 · 0 comments

Comments

@alvarodl
Copy link

Hi. I am having problems similar to described in #776 but working with version 2.9.1.

My scenario is this:

using CommandLine;

namespace QuickStart
{
    class Program
    {
        public class Options
        {
            [Option('i', "input", Required = true, HelpText = "The name of the videos to split. E.g. media split -i file1.mp4 file2.mp4")]
            public IEnumerable<string> Input { get; set; } = new List<string>();

            [Option('s', "seconds", Required = true, HelpText = "A space separated list of seconds to split the video. E.g. media split -s 5 10")]
            public IEnumerable<int> Seconds { get; set; } = new List<int>();
        }

        static void Main(string[] args)
        {
            new Parser(with => { with.IgnoreUnknownArguments = true; })
                .ParseArguments<Options>(args)
                .WithParsed<Options>(o =>
                {
                    Console.WriteLine("Quick Start Example!");
                })
                .WithNotParsed(errors =>
                {
                    foreach (var e in errors)
                    {
                        Console.WriteLine($"Error: {e}");
                    }
                });
        }
    }
}

Being IgnoreUnknownArguments = true when I pass more parameters (ex. --input c:\temp\test.mp4 --seconds 2 4 --test1 xxxx) it returns

Error: CommandLine.BadFormatConversionError
Error: CommandLine.MissingRequiredOptionError (in seconds option)

If I change the type of Seconds to IEnumerable<string> it works correctly (this is going to be my workaround at this moment) but seems like library continues going crazy trying to parse unknown arguments in this scenario.

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