pcapriotti / optparse-applicative

Applicative option parser
BSD 3-Clause "New" or "Revised" License
914 stars 116 forks source link

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

Closed wdanilo closed 11 years ago

wdanilo commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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/pcapriotti/optparse-applicative/issues/58#issuecomment-28778138 .

danse commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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?