summaryrefslogtreecommitdiff
path: root/BackendList.hs
blob: 104444dc20722d72456cece909f120c4266da159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{- git-annex backend list
 - -}

module BackendList (
	supportedBackends,
	parseBackendList,
	lookupBackendName
) where

import Types

-- When adding a new backend, import it here and add it to the list.
import qualified BackendFile
import qualified BackendChecksum
import qualified BackendUrl
supportedBackends = 
	[ BackendFile.backend
	, BackendChecksum.backend
	, BackendUrl.backend
	]

{- 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

{- Looks up a supported backed 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