summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-22 22:03:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-23 01:08:19 -0400
commitfdf02986cf2c7db74cc8ca8ebd2786922652ff9b (patch)
treed6a61cdf01df8b3e635f71a7dc3adfdd43a0a8f8
parent7227dd8f21f24c2ccadd38e1a3dec7b888a23e92 (diff)
find --json
-rw-r--r--Command/Find.hs16
-rw-r--r--Messages.hs10
-rw-r--r--Messages/JSON.hs9
-rw-r--r--debian/changelog3
4 files changed, 28 insertions, 10 deletions
diff --git a/Command/Find.hs b/Command/Find.hs
index 6050ff7bb..91386bbd0 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -28,15 +28,17 @@ start :: FilePath -> (Key, Backend Annex) -> CommandStart
start file (key, _) = do
-- only files inAnnex are shown, unless the user has requested
-- others via a limit
- whenM (liftM2 (||) (inAnnex key) limited) $ do
- f <- Annex.getState Annex.format
- case f of
- Nothing -> liftIO $ putStrLn file
- Just formatter -> liftIO $ putStr $
- Utility.Format.format formatter vars
+ whenM (liftM2 (||) (inAnnex key) limited) $
+ unlessM (showFullJSON vars) $ do
+ f <- Annex.getState Annex.format
+ case f of
+ Nothing -> liftIO $ putStrLn file
+ Just formatter -> liftIO $ putStr $
+ Utility.Format.format formatter $
+ M.fromList vars
stop
where
- vars = M.fromList
+ vars =
[ ("file", file)
, ("key", show key)
, ("backend", keyBackendName key)
diff --git a/Messages.hs b/Messages.hs
index a7f14f485..1294e44f6 100644
--- a/Messages.hs
+++ b/Messages.hs
@@ -20,6 +20,7 @@ module Messages (
warning,
indent,
maybeShowJSON,
+ showFullJSON,
showCustom,
showHeader,
showRaw,
@@ -90,10 +91,17 @@ warning' w = do
indent :: String -> String
indent = join "\n" . map (\l -> " " ++ l) . lines
-{- Shows a JSON value only when in json mode. -}
+{- Shows a JSON fragment only when in json mode. -}
maybeShowJSON :: JSON a => [(String, a)] -> Annex ()
maybeShowJSON v = handle (JSON.add v) q
+{- Shows a complete JSON value, only when in json mode. -}
+showFullJSON :: JSON a => [(String, a)] -> Annex Bool
+showFullJSON v = Annex.getState Annex.output >>= liftIO . go
+ where
+ go Annex.JSONOutput = JSON.complete v >> return True
+ go _ = return False
+
{- Performs an action that outputs nonstandard/customized output, and
- in JSON mode wraps its output in JSON.start and JSON.end, so it's
- a complete JSON document.
diff --git a/Messages/JSON.hs b/Messages/JSON.hs
index a325ef130..f7a031e38 100644
--- a/Messages/JSON.hs
+++ b/Messages/JSON.hs
@@ -9,7 +9,8 @@ module Messages.JSON (
start,
end,
note,
- add
+ add,
+ complete
) where
import Text.JSON
@@ -31,3 +32,9 @@ note s = add [("note", s)]
add :: JSON a => [(String, a)] -> IO ()
add v = putStr $ Stream.add v
+
+complete :: JSON a => [(String, a)] -> IO ()
+complete v = putStr $ concat
+ [ Stream.start v
+ , Stream.end
+ ]
diff --git a/debian/changelog b/debian/changelog
index a27611f55..33d196fa3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,8 +10,9 @@ git-annex (3.20111212) UNRELEASED; urgency=low
* Add --include, which is the same as --not --exclude.
* Can now be built with older git versions (before 1.7.7); the resulting
binary should only be used with old git.
- * Format strings can be specified using the new --find option, to control
+ * Format strings can be specified using the new --format option, to control
what is output by git annex find.
+ * Support git annex find --json
-- Joey Hess <joeyh@debian.org> Mon, 12 Dec 2011 01:57:49 -0400