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

Invalid result with arguments "--enabled --width=1250 --rows=7 --cols=4 --dummy=4" #776

Closed
skanejohan opened this issue Sep 21, 2021 · 0 comments

Comments

@skanejohan
Copy link

I ran into an odd problem with the above arguments. If I set (the unused) "--dummy=3", my application works fine but when I change it to "--dummy=4", I can no longer parse my object. I managed to modify your example application to catch this:

using System;
using CommandLine;

namespace QuickStart
{
    class Program
    {
        public class Options
        {
            [Option('v', "verbose", Required = false)]
            public bool Verbose { get; set; }

            [Option("enabled", Required = false)]
            public bool Enabled { get; set; }

            [Option("width", Required = false)]
            public int Width { get; set; }

            [Option("rows", Required = false)]
            public int Rows { get; set; }

            [Option("cols", Required = false)]
            public int Cols { get; set; }
        }

        static void Main(string[] args)
        {
            new Parser(with => { with.IgnoreUnknownArguments = true; })
                .ParseArguments<Options>(args)
                .WithParsed<Options>(o =>
                {
                    if (o.Verbose)
                    {
                        Console.WriteLine($"Verbose output enabled. Current Arguments: -v {o.Verbose}");
                        Console.WriteLine("Quick Start Example! App is in Verbose mode!");
                    }
                    else
                    {
                        Console.WriteLine($"Current Arguments: -v {o.Verbose}");
                        Console.WriteLine($"  Enabled: {o.Enabled}");
                        Console.WriteLine("Quick Start Example!");
                    }
                })
                .WithNotParsed(errors =>
                {
                    foreach (var e in errors)
                    {
                        Console.WriteLine($"Error: {e} ({((MissingValueOptionError)e).NameInfo.LongName})");
                    }
                });
        }
    }
}

With argument string "--enabled --width=1250 --rows=7 --cols=4 --dummy=3", the application properly indicates that enabled=true but when I change it to "--enabled --width=1250 --rows=7 --cols=4 --dummy=4", it indicates that the "cols" parameter is missing.

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