Remove key:null from git-annex add --json output.
authorJoey Hess <joeyh@joeyh.name>
Fri, 9 Sep 2016 18:26:34 +0000 (14:26 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 9 Sep 2016 18:26:34 +0000 (14:26 -0400)
CHANGELOG
Messages/JSON.hs

index 2e42fb34fff055c9a6623773d9edfbd66f4ef4ed..61831dfd31dbda0c847b8a6eb1176b5ad0054b14 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,7 @@ git-annex (6.20160908) UNRELEASED; urgency=medium
     over ssh etc.
   * Make --json and --quiet work when used with -J.
     Previously, -J override the other options.
+  * Remove key:null from git-annex add --json output.
 
  -- Joey Hess <id@joeyh.name>  Thu, 08 Sep 2016 12:48:55 -0400
 
index 9f8f31c46c5512fc32cc3c6f3b4c5e112c727529..0cceda3f385250fe1d793ef0df554248b4d141a7 100644 (file)
@@ -24,6 +24,7 @@ import qualified Data.Map as M
 import qualified Data.Text as T
 import qualified Data.ByteString.Lazy as B
 import System.IO
+import Data.Maybe
 import Data.Monoid
 import Prelude
 
@@ -84,10 +85,12 @@ data JSONActionItem a = JSONActionItem
        deriving (Show)
 
 instance ToJSON (JSONActionItem a) where
-       toJSON i = object
-               [ "command" .= itemCommand i
-               , "key" .= (toJSON (itemKey i))
-               , "file" .= itemFile i
+       toJSON i = object $ catMaybes
+               [ Just $ "command" .= itemCommand i
+               , case itemKey i of
+                       Nothing -> Nothing
+                       Just k -> Just $ "key" .= toJSON k
+               , Just $ "file" .= itemFile i
                -- itemAdded is not included; must be added later by 'add'
                ]