mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-11-23 06:36:45 +03:00
Merge pull request #94.
This commit is contained in:
commit
428c2ef000
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user