diff options
author | 2016-01-06 12:33:32 -0400 | |
---|---|---|
committer | 2016-01-06 12:33:32 -0400 | |
commit | f906cddf91577c53600a60e4cfbfa3c1fe25d1ab (patch) | |
tree | 60847da3768aa4a702f2785d20c4806ff9ddb119 /Command | |
parent | 452865e80fd68f75cb3b91b9b4d95f45dd249351 (diff) |
whereis --json: Make url list be included in machine-parseable form.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Whereis.hs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/Command/Whereis.hs b/Command/Whereis.hs index 7b8bdf351..ba815f33c 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -7,8 +7,6 @@ module Command.Whereis where -import qualified Data.Map as M - import Common.Annex import Command import Remote @@ -16,6 +14,8 @@ import Logs.Trust import Logs.Web import Remote.Web (getWebUrls) +import qualified Data.Map as M + cmd :: Command cmd = noCommit $ withGlobalOptions (jsonOption : annexedMatchingOptions) $ command "whereis" SectionQuery @@ -65,21 +65,21 @@ perform remotemap key = do -- Since other remotes than the web remote can set urls -- where a key can be downloaded, get and show all such urls -- as a special case. - showRemote "web" =<< getWebUrls key + showRemoteUrls "web" =<< getWebUrls key forM_ (mapMaybe (`M.lookup` remotemap) locations) $ - performRemote key + performRemoteUrls key if null safelocations then stop else next $ return True where copiesplural 1 = "copy" copiesplural _ = "copies" untrustedheader = "The following untrusted locations may also have copies:\n" -performRemote :: Key -> Remote -> Annex () -performRemote key remote = do +performRemoteUrls :: Key -> Remote -> Annex () +performRemoteUrls key remote = do ls <- (++) <$> askremote <*> claimedurls - showRemote (name remote) ls + showRemoteUrls (name remote) ls where askremote = maybe (pure []) (flip id key) (whereisKey remote) claimedurls = do @@ -89,8 +89,10 @@ performRemote key remote = do <$> getUrls key filterM (\u -> (==) <$> pure remote <*> claimingUrl u) us -showRemote :: String -> [String] -> Annex () -showRemote n ls - | null ls = return () - | otherwise = showLongNote $ unlines $ - map (\l -> n ++ ": " ++ l) ls +showRemoteUrls :: String -> [String] -> Annex () +showRemoteUrls nm us + | null us = return () + | otherwise = do + let ls = unlines $ map (\u -> nm ++ ": " ++ u) us + outputMessage noop ('\n' : indent ls ++ "\n") + maybeShowJSON [("urls", us)] |