diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-07-26 13:30:07 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-07-26 13:30:07 -0400 |
commit | 3eb54bb464b4566e5ea5fe9db5addc20231597d0 (patch) | |
tree | 265691703d3ee1c8f64dc6accc7dd0c30fbb3c3b /Messages.hs | |
parent | 4ee3e4194a716273f68641ba0312339ab7c70b8b (diff) |
allow using Aeson for streaming JSON output
Keeping Text.JSON use for now, because it seems a better fit for most of
the commands, which don't use very structured JSON objects, but just output
whatever fields suites them. But this lets Aeson be used when a more
structured data type is available to serialize to JSON.
Diffstat (limited to 'Messages.hs')
-rw-r--r-- | Messages.hs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Messages.hs b/Messages.hs index 050dff950..63f5b10bb 100644 --- a/Messages.hs +++ b/Messages.hs @@ -29,6 +29,7 @@ module Messages ( earlyWarning, warningIO, indent, + JSONChunk(..), maybeShowJSON, showFullJSON, showCustom, @@ -43,7 +44,6 @@ module Messages ( implicitMessage, ) where -import Text.JSON import System.Log.Logger import System.Log.Formatter import System.Log.Handler (setFormatter) @@ -55,6 +55,7 @@ import Types.Messages import Git.FilePath import Messages.Internal import qualified Messages.JSON as JSON +import Utility.JSONStream (JSONChunk(..)) import Types.Key import qualified Annex @@ -181,15 +182,15 @@ warningIO w = do indent :: String -> String indent = intercalate "\n" . map (\l -> " " ++ l) . lines -{- Shows a JSON fragment only when in json mode. -} -maybeShowJSON :: JSON a => [(String, a)] -> Annex () +{- Shows a JSON chunk only when in json mode. -} +maybeShowJSON :: JSONChunk v -> Annex () maybeShowJSON v = withOutputType $ liftIO . go where go JSONOutput = JSON.add v go _ = return () {- Shows a complete JSON value, only when in json mode. -} -showFullJSON :: JSON a => [(String, a)] -> Annex Bool +showFullJSON :: JSONChunk v -> Annex Bool showFullJSON v = withOutputType $ liftIO . go where go JSONOutput = JSON.complete v >> return True |