convert List
This commit is contained in:
parent
a0b2fcc663
commit
e4b3701dfe
2 changed files with 27 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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 '|'
|
||||
|
|
Loading…
Reference in a new issue