From bb2c0603b7757156e0dc31bfa2aa846daf35a7c2 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Tue, 4 Sep 2012 17:25:25 +0100 Subject: [PATCH] Give precedence to custom reader in option builder (#19). --- Options/Applicative/Builder.hs | 4 ++-- tests/Tests.hs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Options/Applicative/Builder.hs b/Options/Applicative/Builder.hs index efb87d0..d89110c 100644 --- a/Options/Applicative/Builder.hs +++ b/Options/Applicative/Builder.hs @@ -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 diff --git a/tests/Tests.hs b/tests/Tests.hs index 6438960..329f590 100644 --- a/tests/Tests.hs +++ b/tests/Tests.hs @@ -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)