2013-05-25 16:44:58 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-04-18 20:04:25 +00:00
|
|
|
- Copyright 2013-2015 Joey Hess <id@joeyh.name>
|
2013-05-25 16:44:58 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-10-28 18:08:38 +00:00
|
|
|
module Command.Wanted where
|
2013-05-25 16:44:58 +00:00
|
|
|
|
|
|
|
import Common.Annex
|
2014-01-03 18:51:32 +00:00
|
|
|
import qualified Annex
|
2013-05-25 16:44:58 +00:00
|
|
|
import Command
|
|
|
|
import qualified Remote
|
|
|
|
import Logs.PreferredContent
|
2014-01-03 18:51:32 +00:00
|
|
|
import Types.Messages
|
2015-04-18 20:04:25 +00:00
|
|
|
import Types.StandardGroups
|
2013-05-25 16:44:58 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-04-18 20:04:25 +00:00
|
|
|
cmd = cmd' "wanted" "get or set preferred content expression"
|
|
|
|
preferredContentMapRaw
|
|
|
|
preferredContentSet
|
|
|
|
|
|
|
|
cmd'
|
|
|
|
:: String
|
|
|
|
-> String
|
|
|
|
-> Annex (M.Map UUID PreferredContentExpression)
|
|
|
|
-> (UUID -> PreferredContentExpression -> Annex ())
|
2015-07-08 16:33:27 +00:00
|
|
|
-> Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd' name desc getter setter = command name SectionSetup desc pdesc (withParams seek)
|
2013-05-25 16:44:58 +00:00
|
|
|
where
|
2015-04-18 20:04:25 +00:00
|
|
|
pdesc = paramPair paramRemote (paramOptional paramExpression)
|
|
|
|
|
|
|
|
seek = withWords start
|
|
|
|
|
|
|
|
start (rname:[]) = go rname (performGet getter)
|
|
|
|
start (rname:expr:[]) = go rname $ \uuid -> do
|
|
|
|
showStart name rname
|
|
|
|
performSet setter expr uuid
|
|
|
|
start _ = error "Specify a repository."
|
|
|
|
|
|
|
|
go rname a = do
|
|
|
|
u <- Remote.nameToUUID rname
|
2013-05-25 16:44:58 +00:00
|
|
|
next $ a u
|
|
|
|
|
2015-04-18 20:04:25 +00:00
|
|
|
performGet :: Ord a => Annex (M.Map a PreferredContentExpression) -> a -> CommandPerform
|
|
|
|
performGet getter a = do
|
2014-01-03 18:51:32 +00:00
|
|
|
Annex.setOutput QuietOutput
|
2015-04-18 20:04:25 +00:00
|
|
|
m <- getter
|
|
|
|
liftIO $ putStrLn $ fromMaybe "" $ M.lookup a m
|
2013-05-25 16:44:58 +00:00
|
|
|
next $ return True
|
|
|
|
|
2015-04-18 20:04:25 +00:00
|
|
|
performSet :: Ord a => (a -> PreferredContentExpression -> Annex ()) -> String -> a -> CommandPerform
|
|
|
|
performSet setter expr a = case checkPreferredContentExpression expr of
|
2013-05-25 16:44:58 +00:00
|
|
|
Just e -> error $ "Parse error: " ++ e
|
|
|
|
Nothing -> do
|
2015-04-18 20:04:25 +00:00
|
|
|
setter a expr
|
2013-05-25 16:44:58 +00:00
|
|
|
next $ return True
|