Skip to content

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

@skanejohan

Description

@skanejohan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions