Merge pull request #94.

This commit is contained in:
Paolo Capriotti 2014-07-23 14:33:18 +01:00
commit 428c2ef000
2 changed files with 11 additions and 7 deletions

View File

@ -10,6 +10,7 @@ module Options.Applicative.Extra (
customExecParser,
customExecParserMaybe,
execParserPure,
handleParseResult,
ParserFailure(..),
ParserResult(..),
ParserPrefs(..),
@ -57,18 +58,21 @@ execParser = customExecParser (prefs idm)
-- | Run a program description with custom preferences.
customExecParser :: ParserPrefs -> ParserInfo a -> IO a
customExecParser pprefs pinfo = do
args <- getArgs
case execParserPure pprefs pinfo args of
Success a -> return a
Failure failure -> do
customExecParser pprefs pinfo
= execParserPure pprefs pinfo <$> getArgs
>>= handleParseResult
-- | Handle `ParserResult`.
handleParseResult :: ParserResult a -> IO a
handleParseResult (Success a) = return a
handleParseResult (Failure failure) = do
progn <- getProgName
let (msg, exit) = execFailure failure progn
case exit of
ExitSuccess -> putStrLn msg
_ -> hPutStrLn stderr msg
exitWith exit
CompletionInvoked compl -> do
handleParseResult (CompletionInvoked compl) = do
progn <- getProgName
msg <- execCompletion compl progn
putStr msg

View File

@ -1,5 +1,5 @@
name: optparse-applicative
version: 0.9.0
version: 0.9.1
synopsis: Utilities and combinators for parsing command line options
description:
Here is a simple example of an applicative option parser: