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 Command
|
|
|
|
import qualified Remote
|
|
|
|
import Logs.PreferredContent
|
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
|
2017-02-16 17:24:16 +00:00
|
|
|
cmd' name desc getter setter = noMessages $
|
|
|
|
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
|
2017-02-16 17:24:16 +00:00
|
|
|
allowMessages
|
2015-04-18 20:04:25 +00:00
|
|
|
showStart name rname
|
|
|
|
performSet setter expr uuid
|
2016-11-16 01:29:54 +00:00
|
|
|
start _ = giveup "Specify a repository."
|
2015-04-18 20:04:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
m <- getter
|
|
|
|
liftIO $ putStrLn $ fromMaybe "" $ M.lookup a m
|
2013-05-25 16:44:58 +00:00
|
|
|
next $ return True
|
|
|
|
|
2016-01-27 16:08:41 +00:00
|
|
|
performSet :: (a -> PreferredContentExpression -> Annex ()) -> String -> a -> CommandPerform
|
2015-04-18 20:04:25 +00:00
|
|
|
performSet setter expr a = case checkPreferredContentExpression expr of
|
2016-11-16 01:29:54 +00:00
|
|
|
Just e -> giveup $ "Parse error: " ++ e
|
2013-05-25 16:44:58 +00:00
|
|
|
Nothing -> do
|
2015-04-18 20:04:25 +00:00
|
|
|
setter a expr
|
2013-05-25 16:44:58 +00:00
|
|
|
next $ return True
|