It should now be relatively easy to customise the appearance of the generated
help text.
For example, in #54, @amigalemming asks for a way to get rid of the usage line
when a specific error message is displayed. This is now easy to achieve:
exec :: ParserPrefs -> ParserInfo a -> IO a
exec pprefs pinfo = do
res <- execParserPure pprefs pinfo <$> getArgs
let f h | isEmpty (helpError h) = h
| otherwise = h { helpUsage = mempty }
handleParseResult (overFailure f res)
The plan is to keep the parser execution API as lean as possible. Once the
deprecated definitions are removed, it will be down to essentially three
functions:
- `execParser`: for quick and dirty usage of the library
- `customExecParser`: for general use
- `execParserPure`: when maximum control or customisation is needed
All the other convenience functions can be obtained easily using
`execParserPure` and other utilities like `handleParseResult` and
`getParseResult`.
This should make it easier to define custom variants of `execParser`. For
example, here is a function to print the help text of a parser:
showHelpText :: ParserPrefs -> ParserInfo a -> IO ()
showHelpText pprefs pinfo = handleParseResult . Failure $
parserFailure pprefs pinfo ShowHelpText mempty
and here is the function requested by #57:
execParserPure' :: ParserPrefs -> ParserInfo a -> [String] -> ParserResult a
execParserPure' pprefs pinfo [] = Failure $
parserFailure pprefs pinfo ShowHelpText mempty
execParserPure' pprefs pinfo args = execParserPure pprefs pinfo args
This commit implements the plan described in the ticket:
- the `reader` modifier is gone, as well as the `optReader` field of
`OptionFields`
- `option` now takes the reader as argument
- `nullOption` is now deprecated in favour of `option`
- added `strArgument` as a synonym for `argument str`, to mirror `strOption`
Since tasty depends on optparse-applicative, I've had to move the tests to a
separate package to avoid the cyclic dependency. Also, since updates to
optparse-applicative might break the build for tasty, the test package does not
actually depend on optparse-applicative, but includes its code directly.