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

MissingRequiredOptionError when specifying required Value after enumerable Options #91

Closed
ericnewton76 opened this issue Nov 4, 2017 · 6 comments

Comments

@ericnewton76
Copy link
Member

Issue by SuperFXMaster
Tuesday Oct 11, 2016 at 19:24 GMT
Originally opened as gsscoder/commandline#361


The following options class:

public class CommandLineOptions
{
    [Value(0, Required = true)]
    public string InputFileName { get; set; }

    [Option('o', "output")]
    public string OutputFileName { get; set; }

    [Option('i', "include", Separator = ',')]
    public IEnumerable<string> Included { get; set; }

    [Option('e', "exclude", Separator = ',')]
    public IEnumerable<string> Excluded { get; set; }
}

When provided to the default parser, with the commandline app.exe --exclude=a,b InputFile.txt results in a MissingRequiredOptionError: A required value not bound to option name is missing. I expected the library to accept InputFileName = InputFile.txt and --exclude=a,b as Excluded = { "a", "b" }. Is there something else required to make this work as I expect, or is it a bug?

@ericnewton76 ericnewton76 added this to the 2.0.x-stable milestone Nov 4, 2017
@ericnewton76
Copy link
Member Author

Comment by nemec
Tuesday Oct 11, 2016 at 19:57 GMT


Yes, I think that's a bug. If you set Required=false you'll see that a, b, and InputFile.txt are all part of Included. Additionally, the "EnableDashDash" setting doesn't work either:

void Main()
{
    var p = new Parser(s =>
    {
        s.EnableDashDash = true;
    });
    var result = p.ParseArguments<CommandLineOptions>("--exclude=a,b -- InputFile.txt".Split());
    result.WithNotParsed(e => e.Dump());
    result.WithParsed(d => d.Dump());
}

public class CommandLineOptions
{
    [Value(0, Required = true)]
    public string InputFileName { get; set; }

    [Option('o', "output")]
    public string OutputFileName { get; set; }

    [Option('i', "include", Separator = ',')]
    public IEnumerable<string> Included { get; set; }

    [Option('e', "exclude", Separator = ',')]
    public IEnumerable<string> Excluded { get; set; }
}

@ericnewton76
Copy link
Member Author

Comment by SuperFXMaster
Wednesday Oct 12, 2016 at 16:20 GMT


As a workaround, the commandline --exclude=a,b --output=OutFile InFile works fine, just as -e a b c -o OutFile InFile does. It seems like the problem arises when the --exclude option is directly before the Required parameter.

@ericnewton76
Copy link
Member Author

Comment by anthonylangsworth
Saturday Oct 22, 2016 at 11:50 GMT


This appears to be fixed in the master branch, @SuperFXMaster and @nemec . I cannot reproduce the issue. Please let me know if I am incorrect.

@ericnewton76
Copy link
Member Author

Comment by nemec
Saturday Nov 05, 2016 at 07:01 GMT


I'm still having issues on the master branch with the code snippet I posted above, as well as @SuperFXMaster's.

@ericnewton76
Copy link
Member Author

Comment by hugener
Monday Mar 13, 2017 at 18:21 GMT


Had quick look into this and could let the example above to run by changing the order of parameters in Concat in the following line:
https://github.com/gsscoder/commandline/blob/master/src/CommandLine/Core/Tokenizer.cs#L54
The changed line becomes:
return tokenizerResult.Map(tokens => values.Concat(tokens));

I'm not sure it's valid for other cases though. Maybe someone who knows more about it can have a look. It would be nice to get a stable version.

@rmunn
Copy link
Contributor

rmunn commented Aug 20, 2020

This will be fixed by #684 once it's merged in.

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

No branches or pull requests

3 participants