From c882b3e9c5dd6dbb28818e6ebfbe8b41b88c9cd3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Jul 2015 20:46:48 -0400 Subject: convert List --- CmdLine/GitAnnex.hs | 4 ++-- Command/List.hs | 42 +++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs index c60e7ecb6..6677f3b29 100644 --- a/CmdLine/GitAnnex.hs +++ b/CmdLine/GitAnnex.hs @@ -59,7 +59,7 @@ import qualified Command.PreCommit import qualified Command.Find import qualified Command.FindRef import qualified Command.Whereis ---import qualified Command.List +import qualified Command.List --import qualified Command.Log import qualified Command.Merge import qualified Command.ResolveMerge @@ -186,7 +186,7 @@ cmds = , Command.Find.cmd , Command.FindRef.cmd , Command.Whereis.cmd --- , Command.List.cmd + , Command.List.cmd -- , Command.Log.cmd , Command.Merge.cmd , Command.ResolveMerge.cmd diff --git a/Command/List.hs b/Command/List.hs index 723f53b46..c912e8c3f 100644 --- a/Command/List.hs +++ b/Command/List.hs @@ -20,29 +20,37 @@ import Remote import Logs.Trust import Logs.UUID import Annex.UUID -import qualified Annex import Git.Types (RemoteName) cmd :: Command -cmd = noCommit $ withOptions (allrepos : annexedMatchingOptions) $ +cmd = noCommit $ withGlobalOptions annexedMatchingOptions $ command "list" SectionQuery "show which remotes contain files" - paramPaths (withParams seek) + paramPaths (seek <$$> optParser) -allrepos :: Option -allrepos = flagOption [] "allrepos" "show all repositories, not only remotes" +data ListOptions = ListOptions + { listThese :: CmdParams + , allRepos :: Bool + } -seek :: CmdParams -> CommandSeek -seek ps = do - list <- getList +optParser :: CmdParamsDesc -> Parser ListOptions +optParser desc = ListOptions + <$> cmdParams desc + <*> switch + ( long "allrepos" + <> help "show all repositories, not only remotes" + ) + +seek :: ListOptions -> CommandSeek +seek o = do + list <- getList o printHeader list - withFilesInGit (whenAnnexed $ start list) ps + withFilesInGit (whenAnnexed $ start list) (listThese o) -getList :: Annex [(UUID, RemoteName, TrustLevel)] -getList = ifM (Annex.getFlag $ optionName allrepos) - ( nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAllUUIDs) - , getRemotes - ) +getList :: ListOptions -> Annex [(UUID, RemoteName, TrustLevel)] +getList o + | allRepos o = nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAllUUIDs) + | otherwise = getRemotes where getRemotes = do rs <- remoteList @@ -60,7 +68,7 @@ getList = ifM (Annex.getFlag $ optionName allrepos) filter (\t -> thd3 t /= DeadTrusted) rs3 printHeader :: [(UUID, RemoteName, TrustLevel)] -> Annex () -printHeader l = liftIO $ putStrLn $ header $ map (\(_, n, t) -> (n, t)) l +printHeader l = liftIO $ putStrLn $ lheader $ map (\(_, n, t) -> (n, t)) l start :: [(UUID, RemoteName, TrustLevel)] -> FilePath -> Key -> CommandStart start l file key = do @@ -70,8 +78,8 @@ start l file key = do type Present = Bool -header :: [(RemoteName, TrustLevel)] -> String -header remotes = unlines (zipWith formatheader [0..] remotes) ++ pipes (length remotes) +lheader :: [(RemoteName, TrustLevel)] -> String +lheader remotes = unlines (zipWith formatheader [0..] remotes) ++ pipes (length remotes) where formatheader n (remotename, trustlevel) = pipes n ++ remotename ++ trust trustlevel pipes = flip replicate '|' -- cgit v1.2.3