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.
This commit is contained in:
parent
fdd87d8e55
commit
a030d0a8b7
10 changed files with 52 additions and 33 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue