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
|
start file (key, _) = do
|
||||||
-- only files inAnnex are shown, unless the user has requested
|
-- only files inAnnex are shown, unless the user has requested
|
||||||
-- others via a limit
|
-- others via a limit
|
||||||
whenM (liftM2 (||) (inAnnex key) limited) $ do
|
whenM (liftM2 (||) (inAnnex key) limited) $
|
||||||
f <- Annex.getState Annex.format
|
unlessM (showFullJSON vars) $ do
|
||||||
case f of
|
f <- Annex.getState Annex.format
|
||||||
Nothing -> liftIO $ putStrLn file
|
case f of
|
||||||
Just formatter -> liftIO $ putStr $
|
Nothing -> liftIO $ putStrLn file
|
||||||
Utility.Format.format formatter vars
|
Just formatter -> liftIO $ putStr $
|
||||||
|
Utility.Format.format formatter $
|
||||||
|
M.fromList vars
|
||||||
stop
|
stop
|
||||||
where
|
where
|
||||||
vars = M.fromList
|
vars =
|
||||||
[ ("file", file)
|
[ ("file", file)
|
||||||
, ("key", show key)
|
, ("key", show key)
|
||||||
, ("backend", keyBackendName key)
|
, ("backend", keyBackendName key)
|
||||||
|
|
10
Messages.hs
10
Messages.hs
|
@ -20,6 +20,7 @@ module Messages (
|
||||||
warning,
|
warning,
|
||||||
indent,
|
indent,
|
||||||
maybeShowJSON,
|
maybeShowJSON,
|
||||||
|
showFullJSON,
|
||||||
showCustom,
|
showCustom,
|
||||||
showHeader,
|
showHeader,
|
||||||
showRaw,
|
showRaw,
|
||||||
|
@ -90,10 +91,17 @@ warning' w = do
|
||||||
indent :: String -> String
|
indent :: String -> String
|
||||||
indent = join "\n" . map (\l -> " " ++ l) . lines
|
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 :: JSON a => [(String, a)] -> Annex ()
|
||||||
maybeShowJSON v = handle (JSON.add v) q
|
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
|
{- Performs an action that outputs nonstandard/customized output, and
|
||||||
- in JSON mode wraps its output in JSON.start and JSON.end, so it's
|
- in JSON mode wraps its output in JSON.start and JSON.end, so it's
|
||||||
- a complete JSON document.
|
- a complete JSON document.
|
||||||
|
|
|
@ -9,7 +9,8 @@ module Messages.JSON (
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
note,
|
note,
|
||||||
add
|
add,
|
||||||
|
complete
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Text.JSON
|
import Text.JSON
|
||||||
|
@ -31,3 +32,9 @@ note s = add [("note", s)]
|
||||||
|
|
||||||
add :: JSON a => [(String, a)] -> IO ()
|
add :: JSON a => [(String, a)] -> IO ()
|
||||||
add v = putStr $ Stream.add v
|
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.
|
* Add --include, which is the same as --not --exclude.
|
||||||
* Can now be built with older git versions (before 1.7.7); the resulting
|
* Can now be built with older git versions (before 1.7.7); the resulting
|
||||||
binary should only be used with old git.
|
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.
|
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
|
-- Joey Hess <joeyh@debian.org> Mon, 12 Dec 2011 01:57:49 -0400
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue