I’m using the optparse-applicative library in an application that takes multiple strings on the command line and performs an action on each one. My first try was this:
arguments Just
( metavar "EXPR"
& help "Expressions to render, in zero-based De Bruijn index notation" )
Unfortunately, this allows running the program with no arguments, even though it doesn’t make much sense.
My second attempt involved parsing the first argument separately, then consing it to the remainder of the list:
(:) <$> argument Just ( metavar "EXPR" )
<*> arguments Just ( metavar "EXPR" )
This should have worked, but it didn’t: when called with --help, the parser gobbles it up and processes it instead of displaying the help text.
So my question is: how do I configure optparse to require at least one argument?
Okay – I’ve reported this issue to the author of the library (Paolo Capriotti). He replied:
In other words, he added a new function
arguments1to do what I described. That function has been available since version 0.5.So now my code looks like this:
Thanks, Paolo!