summaryrefslogtreecommitdiff
path: root/Messages
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-01 15:16:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-01 15:22:06 -0400
commit2f4d4d1c4552a93a5f26a8a0a713e3916612329e (patch)
treea75ee41d85fc2c49ce8adf26a8c22e4f6ed6b944 /Messages
parent57dd34c6be5dbc01286108fd943ff9e02956e8aa (diff)
basic json support
This includes a generic JSONStream library built on top of Text.JSON (somewhat hackishly). It would be possible to stream out a single json document describing all actions, but it's probably better for consumers if they can expect one json document per line, so I did it that way instead. Output from external programs used for transferring files is not currently hidden when outputting json, which probably makes it not very useful there. This may be dealt with if there is demand for json output for --get or --move to be parsable. The version, status, and find subcommands have hand-crafted output and don't do json. The whereis subcommand needs to be modified to produce useful json.
Diffstat (limited to 'Messages')
-rw-r--r--Messages/JSON.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Messages/JSON.hs b/Messages/JSON.hs
new file mode 100644
index 000000000..ee6ea34a3
--- /dev/null
+++ b/Messages/JSON.hs
@@ -0,0 +1,23 @@
+{- git-annex JSON output
+ -
+ - Copyright 2011 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Messages.JSON (
+ start,
+ end,
+ note
+) where
+
+import qualified Utility.JSONStream as Stream
+
+start :: String -> String -> IO ()
+start command file = putStr $ Stream.start [("command", command), ("file", file)]
+
+end :: Bool -> IO ()
+end b = putStr $ Stream.add [("success", b)] ++ Stream.end
+
+note :: String -> IO ()
+note s = putStr $ Stream.add [("note", s)]