Give precedence to custom reader in option builder (#19).

This commit is contained in:
Paolo Capriotti 2012-09-04 17:25:25 +01:00
parent 2881d647f2
commit bb2c0603b7
2 changed files with 14 additions and 2 deletions

View File

@ -365,11 +365,11 @@ nullOption m = mkParser d g rdr
-- | Builder for an option taking a 'String' argument. -- | Builder for an option taking a 'String' argument.
strOption :: Mod OptionFields String -> Parser String 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. -- | Builder for an option using the 'auto' reader.
option :: Read a => Mod OptionFields a -> Parser a option :: Read a => Mod OptionFields a -> Parser a
option m = nullOption $ m & reader auto option m = nullOption $ reader auto & m
-- | Modifier for 'ParserInfo'. -- | Modifier for 'ParserInfo'.
newtype InfoMod a = InfoMod newtype InfoMod a = InfoMod

View File

@ -191,5 +191,17 @@ case_bind_usage = do
Right val -> Right val ->
assertFailure $ "unexpected result " ++ show 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 :: IO ()
main = $(defaultMainGenerator) main = $(defaultMainGenerator)