aboutsummaryrefslogtreecommitdiff
path: root/Command/List.hs
diff options
context:
space:
mode:
authorGravatar Antoine Beaupré <anarcat@koumbit.org>2013-09-19 14:16:28 -0400
committerGravatar Antoine Beaupré <anarcat@koumbit.org>2013-09-19 14:16:55 -0400
commitdcd29f4cf57d8bf3bc84bd3368b1e5e09ed8d85e (patch)
tree58eef8b88986f2f22f5dcc679a41c01f8554ff79 /Command/List.hs
parentb75aa5d1d0848ae54d6e85ada1b8247946afa5cc (diff)
rename remotes to list
Diffstat (limited to 'Command/List.hs')
-rw-r--r--Command/List.hs64
1 files changed, 64 insertions, 0 deletions
diff --git a/Command/List.hs b/Command/List.hs
new file mode 100644
index 000000000..61f77f7f3
--- /dev/null
+++ b/Command/List.hs
@@ -0,0 +1,64 @@
+{- git-annex command
+ -
+ - Copyright 2013 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.List where
+
+import qualified Data.Set as S
+
+import Common.Annex
+import Command
+import Remote
+import Logs.Trust
+import Annex.UUID
+
+def :: [Command]
+def = [noCommit $ command "list" paramPaths seek
+ SectionQuery "show which remotes contain files"]
+
+seek :: [CommandSeek]
+seek =
+ [ withValue getList $ \l -> withNothing $ startHeader l
+ , withValue getList $ \l -> withFilesInGit $ whenAnnexed $ start l
+ ]
+
+getList :: Annex [(UUID, RemoteName, TrustLevel)]
+getList = do
+ rs <- remoteList
+ ts <- mapM (lookupTrust . uuid) rs
+ hereu <- getUUID
+ heretrust <- lookupTrust hereu
+ return $ (hereu, "here", heretrust) : zip3 (map uuid rs) (map name rs) ts
+
+startHeader :: [(UUID, RemoteName, TrustLevel)] -> CommandStart
+startHeader l = do
+ liftIO $ putStrLn $ header $ map (\(_, n, t) -> (n, t)) l
+ stop
+
+start :: [(UUID, RemoteName, TrustLevel)] -> FilePath -> (Key, Backend) -> CommandStart
+start l file (key, _) = do
+ ls <- S.fromList <$> keyLocations key
+ liftIO $ putStrLn $ format (map (\(u, _, t) -> (t, S.member u ls)) l) file
+ stop
+
+type RemoteName = String
+type Present = Bool
+
+header :: [(RemoteName, TrustLevel)] -> String
+header remotes = (unlines $ zipWith formatheader [0..] remotes) ++ (pipes (length remotes))
+ where
+ formatheader n (remotename, trustlevel) = (pipes n) ++ remotename ++ (trust trustlevel)
+ pipes = flip replicate '|'
+ trust UnTrusted = " (untrusted)"
+ trust _ = ""
+
+format :: [(TrustLevel, Present)] -> FilePath -> String
+format remotes file = thereMap ++ " " ++ file
+ where
+ thereMap = concatMap there remotes
+ there (UnTrusted, True) = "x"
+ there (_, True) = "X"
+ there (_, False) = "_"