git-annex/BackendList.hs

38 lines
941 B
Haskell
Raw Normal View History

2010-10-10 22:05:37 +00:00
{- git-annex backend list
- -}
2010-10-11 21:52:46 +00:00
module BackendList (
supportedBackends,
parseBackendList,
lookupBackendName
) where
2010-10-10 22:05:37 +00:00
2010-10-14 06:52:17 +00:00
import BackendTypes
2010-10-11 21:19:55 +00:00
2010-10-10 22:05:37 +00:00
-- When adding a new backend, import it here and add it to the list.
2010-10-15 23:33:10 +00:00
import qualified Backend.WORM
import qualified Backend.SHA1
import qualified Backend.URL
2010-10-10 22:05:37 +00:00
supportedBackends =
2010-10-15 23:33:10 +00:00
[ Backend.WORM.backend
, Backend.SHA1.backend
, Backend.URL.backend
2010-10-10 22:05:37 +00:00
]
{- Parses a string with a list of backend names into
- a list of Backend objects. If the list is empty,
- defaults to supportedBackends. -}
parseBackendList :: String -> [Backend]
parseBackendList s =
if (length s == 0)
then supportedBackends
else map (lookupBackendName) $ words s
2010-10-15 00:05:04 +00:00
{- Looks up a supported backend by name. -}
lookupBackendName :: String -> Backend
lookupBackendName s =
if ((length matches) /= 1)
then error $ "unknown backend " ++ s
else matches !! 0
where matches = filter (\b -> s == name b) supportedBackends