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

Enumerable of Enum doesn't work if followed by Values #617

Closed
usr-sse2 opened this issue Apr 16, 2020 · 2 comments
Closed

Enumerable of Enum doesn't work if followed by Values #617

usr-sse2 opened this issue Apr 16, 2020 · 2 comments

Comments

@usr-sse2
Copy link

I have such options:

[Option("fm",  Separator=',', Default = new[] { FMode.S })]  
public IEnumerable<FMode> Mode { get; set; }
	 
[Option('q')]
public bool q { get;set; }
	 
[Value(0)]
public IList<string> Files { get; set; }

If I run my application with --fm D,C a.txt arguments, it says that option 'fm' is defined with a bad format. If I put any option between 'fm' and the value list, for example, --fm D,C -q a.txt, it is parsed successfully. You can check it in a fiddle: https://dotnetfiddle.net/yt5L9K

@rmunn
Copy link
Contributor

rmunn commented Aug 20, 2020

This is caused by the fact that IEnumerable options try to grab every subsequent non-option argument that follows them, regardless of whether it makes sense, which is why it's grabbing the a.txt and trying to parse that as an FMode enum. I believe that this is non-intuitive behavior and that the way IEnumerable options should work should be changed as follows:

  • If there is no separator given, grab all available non-option args
  • If a separator is given, but the next non-option arg doesn't contain the separator, continue to grab all available non-option args
  • If a separator is given, and the next non-option arg contains the separator, STOP and don't grab any further values (this would be new behavior)

Currently the code follows the first two of those rules, but not the third.

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants