find --json
This commit is contained in:
parent
7227dd8f21
commit
fdf02986cf
4 changed files with 28 additions and 10 deletions
|
@ -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
|
||||
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 vars
|
||||
Utility.Format.format formatter $
|
||||
M.fromList vars
|
||||
stop
|
||||
where
|
||||
vars = M.fromList
|
||||
vars =
|
||||
[ ("file", file)
|
||||
, ("key", show key)
|
||||
, ("backend", keyBackendName key)
|
||||
|
|
10
Messages.hs
10
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.
|
||||
|
|
|
@ -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
|
||||
]
|
||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue