summaryrefslogtreecommitdiff
path: root/Command/GroupWanted.hs
blob: 859a39c1b9762bafeb87ea35e8ab1861aa332460 (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
38
39
40
41
42
43
44
45
{- git-annex command
 -
 - Copyright 2015 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.GroupWanted where

import Common.Annex
import qualified Annex
import Command
import Logs.PreferredContent
import Types.Messages
import Types.Group

import qualified Data.Map as M

cmd :: [Command]
cmd = [command "groupwanted" (paramPair paramGroup (paramOptional paramExpression)) seek
	SectionSetup "get or set groupwanted expression"]

seek :: CommandSeek
seek = withWords start

start :: [String] -> CommandStart
start (g:[]) = next $ performGet g
start (g:expr:[]) = do
	showStart "groupwanted" g
	next $ performSet g expr
start _ = error "Specify a group."

performGet :: Group -> CommandPerform
performGet g = do
	Annex.setOutput QuietOutput
	m <- groupPreferredContentMapRaw
	liftIO $ putStrLn $ fromMaybe "" $ M.lookup g m
	next $ return True

performSet :: Group -> String -> CommandPerform
performSet g expr = case checkPreferredContentExpression expr of
	Just e -> error $ "Parse error: " ++ e
	Nothing -> do
		groupPreferredContentSet g expr
		next $ return True