aboutsummaryrefslogtreecommitdiff
path: root/Messages
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-07-26 13:30:07 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-07-26 13:30:07 -0400
commit3eb54bb464b4566e5ea5fe9db5addc20231597d0 (patch)
tree265691703d3ee1c8f64dc6accc7dd0c30fbb3c3b /Messages
parent4ee3e4194a716273f68641ba0312339ab7c70b8b (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')
-rw-r--r--Messages/JSON.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/Messages/JSON.hs b/Messages/JSON.hs
index fa829a76c..6e89693fc 100644
--- a/Messages/JSON.hs
+++ b/Messages/JSON.hs
@@ -1,6 +1,6 @@
-{- git-annex JSON output
+{- git-annex command-line JSON output and input
-
- - Copyright 2011 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -21,7 +21,7 @@ import Types.Key
import Data.Maybe
start :: String -> Maybe FilePath -> Maybe Key -> IO ()
-start command file key = putStr $ Stream.start $ catMaybes
+start command file key = putStr $ Stream.start $ Stream.JSONObject $ catMaybes
[ part "command" (Just command)
, part "file" file
, part "key" (fmap key2file key)
@@ -31,15 +31,15 @@ start command file key = putStr $ Stream.start $ catMaybes
part l (Just v) = Just (l, v)
end :: Bool -> IO ()
-end b = putStr $ Stream.add [("success", b)] ++ Stream.end
+end b = putStr $ Stream.add (Stream.JSONObject [("success", b)]) ++ Stream.end
note :: String -> IO ()
-note s = add [("note", s)]
+note s = add (Stream.JSONObject [("note", s)])
-add :: JSON a => [(String, a)] -> IO ()
-add v = putStr $ Stream.add v
+add :: Stream.JSONChunk a -> IO ()
+add = putStr . Stream.add
-complete :: JSON a => [(String, a)] -> IO ()
+complete :: Stream.JSONChunk a -> IO ()
complete v = putStr $ Stream.start v ++ Stream.end
-- A value that can be displayed either normally, or as JSON.