From 19eed1744b87d97ad6f65bd2a2215febc35d0982 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Wed, 30 Jul 2014 19:15:57 +0100 Subject: [PATCH] Add `Show` instance for `ParserResult` (fixes #95). --- CHANGELOG.md | 2 ++ Options/Applicative/Types.hs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2104035..6b80fa53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Added low-level function to handle parse results (pull request \#94). +- `ParserResult` now has a `Show` instance (see issue \#95). + - Fixed bugs * \#93 - Formatting problem for several sub-parsers diff --git a/Options/Applicative/Types.hs b/Options/Applicative/Types.hs index 370fbf9b..7d2fa53e 100644 --- a/Options/Applicative/Types.hs +++ b/Options/Applicative/Types.hs @@ -236,14 +236,25 @@ instance Monoid Completer where newtype CompletionResult = CompletionResult { execCompletion :: String -> IO String } +instance Show CompletionResult where + showsPrec p _ = showParen (p > 10) $ + showString "CompletionResult _" + newtype ParserFailure = ParserFailure { execFailure :: String -> (String, ExitCode) } +instance Show ParserFailure where + showsPrec p (ParserFailure f) + = showParen (p > 10) + $ showString "ParserFailure " + . showsPrec 11 (f "") + -- | Result of 'execParserPure'. data ParserResult a = Success a | Failure ParserFailure | CompletionInvoked CompletionResult + deriving Show type Args = [String]