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

Optparse hanging infinitely & support for multiple usage of the same flag #58

Closed
wdanilo opened this issue Nov 19, 2013 · 5 comments
Closed

Comments

@wdanilo
Copy link

wdanilo commented Nov 19, 2013

Hi!
Would it be possible to add support for multiple usage of the same flag?
I would love to allow users to use arguments like this myprog --dump ast --dump va --dump test and I would like to get array of String's as a result.

And here is what I was trying (what was natural to me, because I have some Parsec background) and it hanged optparse when printing help:

[...] many (strOption (long "dump" <> value "" <> metavar "DUMP")) [...]

Thank you.

@pcapriotti
Copy link
Owner

It is possible, but you can't repeat an option with a default value, because in that case you get an infinite list as a result, and that makes the parser diverge. Just remove value "" from your parser and it will work. It doesn't make sense to have a default there, anyway.

@wdanilo
Copy link
Author

wdanilo commented Nov 19, 2013

Thank you very much! I'm sorry for posting an incorrect bug report.

2013/11/19 Paolo Capriotti notifications@github.com

It is possible, but you can't repeat an option with a default value,
because in that case you get an infinite list as a result, and that makes
the parser diverge. Just remove value "" from your parser and it will
work. It doesn't make sense to have a default there, anyway.


Reply to this email directly or view it on GitHubhttps://github.com//issues/58#issuecomment-28778138
.

@danse
Copy link

danse commented Mar 20, 2018

i stumbled upon this same problem today. i tried a clumsy option (many str) and got a scary runtime loop. this seems like a noob trap, i propose to improve the README with this example, i'll put a quick patch together

@danse
Copy link

danse commented Mar 20, 2018

actually the best solution would probably be a function like manyStrOption = many strOption, where the haddock can explain that this is a simple alias. to me this seems the more findable way to avoid similar error to new users of the library, and make adoption easier ... i see that you kept the interface very dry and orthogonal though so you probably want to keep it so

@danse
Copy link

danse commented Mar 20, 2018

it could be modified as in #295 but it's not very visible, maybe we could have some examples of this usage elsewhere, or point to a guide which goes through applicative parsing?

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

3 participants