mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-11-27 11:56:20 +03:00
Give precedence to custom reader in option builder (#19).
This commit is contained in:
parent
2881d647f2
commit
bb2c0603b7
@ -365,11 +365,11 @@ nullOption m = mkParser d g rdr
|
||||
|
||||
-- | Builder for an option taking a 'String' argument.
|
||||
strOption :: Mod OptionFields String -> Parser String
|
||||
strOption m = nullOption $ m & reader str
|
||||
strOption m = nullOption $ reader str & m
|
||||
|
||||
-- | Builder for an option using the 'auto' reader.
|
||||
option :: Read a => Mod OptionFields a -> Parser a
|
||||
option m = nullOption $ m & reader auto
|
||||
option m = nullOption $ reader auto & m
|
||||
|
||||
-- | Modifier for 'ParserInfo'.
|
||||
newtype InfoMod a = InfoMod
|
||||
|
@ -191,5 +191,17 @@ case_bind_usage = do
|
||||
Right val ->
|
||||
assertFailure $ "unexpected result " ++ show val
|
||||
|
||||
case_issue_19 :: Assertion
|
||||
case_issue_19 = do
|
||||
let p = option
|
||||
( short 'x'
|
||||
& reader (Just . str)
|
||||
& value Nothing )
|
||||
i = info (p <**> helper) idm
|
||||
result = run i ["-x", "foo"]
|
||||
case result of
|
||||
Left _ -> assertFailure "unexpected parse error"
|
||||
Right r -> Just "foo" @=? r
|
||||
|
||||
main :: IO ()
|
||||
main = $(defaultMainGenerator)
|
||||
|
Loading…
Reference in New Issue
Block a user