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.Find
|
||||||
import qualified Command.FindRef
|
import qualified Command.FindRef
|
||||||
import qualified Command.Whereis
|
import qualified Command.Whereis
|
||||||
--import qualified Command.List
|
import qualified Command.List
|
||||||
--import qualified Command.Log
|
--import qualified Command.Log
|
||||||
import qualified Command.Merge
|
import qualified Command.Merge
|
||||||
import qualified Command.ResolveMerge
|
import qualified Command.ResolveMerge
|
||||||
|
@ -186,7 +186,7 @@ cmds =
|
||||||
, Command.Find.cmd
|
, Command.Find.cmd
|
||||||
, Command.FindRef.cmd
|
, Command.FindRef.cmd
|
||||||
, Command.Whereis.cmd
|
, Command.Whereis.cmd
|
||||||
-- , Command.List.cmd
|
, Command.List.cmd
|
||||||
-- , Command.Log.cmd
|
-- , Command.Log.cmd
|
||||||
, Command.Merge.cmd
|
, Command.Merge.cmd
|
||||||
, Command.ResolveMerge.cmd
|
, Command.ResolveMerge.cmd
|
||||||
|
|
|
@ -20,29 +20,37 @@ import Remote
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
import Logs.UUID
|
import Logs.UUID
|
||||||
import Annex.UUID
|
import Annex.UUID
|
||||||
import qualified Annex
|
|
||||||
import Git.Types (RemoteName)
|
import Git.Types (RemoteName)
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = noCommit $ withOptions (allrepos : annexedMatchingOptions) $
|
cmd = noCommit $ withGlobalOptions annexedMatchingOptions $
|
||||||
command "list" SectionQuery
|
command "list" SectionQuery
|
||||||
"show which remotes contain files"
|
"show which remotes contain files"
|
||||||
paramPaths (withParams seek)
|
paramPaths (seek <$$> optParser)
|
||||||
|
|
||||||
allrepos :: Option
|
data ListOptions = ListOptions
|
||||||
allrepos = flagOption [] "allrepos" "show all repositories, not only remotes"
|
{ listThese :: CmdParams
|
||||||
|
, allRepos :: Bool
|
||||||
|
}
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
optParser :: CmdParamsDesc -> Parser ListOptions
|
||||||
seek ps = do
|
optParser desc = ListOptions
|
||||||
list <- getList
|
<$> cmdParams desc
|
||||||
|
<*> switch
|
||||||
|
( long "allrepos"
|
||||||
|
<> help "show all repositories, not only remotes"
|
||||||
|
)
|
||||||
|
|
||||||
|
seek :: ListOptions -> CommandSeek
|
||||||
|
seek o = do
|
||||||
|
list <- getList o
|
||||||
printHeader list
|
printHeader list
|
||||||
withFilesInGit (whenAnnexed $ start list) ps
|
withFilesInGit (whenAnnexed $ start list) (listThese o)
|
||||||
|
|
||||||
getList :: Annex [(UUID, RemoteName, TrustLevel)]
|
getList :: ListOptions -> Annex [(UUID, RemoteName, TrustLevel)]
|
||||||
getList = ifM (Annex.getFlag $ optionName allrepos)
|
getList o
|
||||||
( nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAllUUIDs)
|
| allRepos o = nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAllUUIDs)
|
||||||
, getRemotes
|
| otherwise = getRemotes
|
||||||
)
|
|
||||||
where
|
where
|
||||||
getRemotes = do
|
getRemotes = do
|
||||||
rs <- remoteList
|
rs <- remoteList
|
||||||
|
@ -60,7 +68,7 @@ getList = ifM (Annex.getFlag $ optionName allrepos)
|
||||||
filter (\t -> thd3 t /= DeadTrusted) rs3
|
filter (\t -> thd3 t /= DeadTrusted) rs3
|
||||||
|
|
||||||
printHeader :: [(UUID, RemoteName, TrustLevel)] -> Annex ()
|
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 :: [(UUID, RemoteName, TrustLevel)] -> FilePath -> Key -> CommandStart
|
||||||
start l file key = do
|
start l file key = do
|
||||||
|
@ -70,8 +78,8 @@ start l file key = do
|
||||||
|
|
||||||
type Present = Bool
|
type Present = Bool
|
||||||
|
|
||||||
header :: [(RemoteName, TrustLevel)] -> String
|
lheader :: [(RemoteName, TrustLevel)] -> String
|
||||||
header remotes = unlines (zipWith formatheader [0..] remotes) ++ pipes (length remotes)
|
lheader remotes = unlines (zipWith formatheader [0..] remotes) ++ pipes (length remotes)
|
||||||
where
|
where
|
||||||
formatheader n (remotename, trustlevel) = pipes n ++ remotename ++ trust trustlevel
|
formatheader n (remotename, trustlevel) = pipes n ++ remotename ++ trust trustlevel
|
||||||
pipes = flip replicate '|'
|
pipes = flip replicate '|'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue