diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-02-06 15:12:42 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-02-06 15:12:42 -0400 |
commit | faa6b2cdd7e62e221ccda3890fd1da32713cec8f (patch) | |
tree | 0587650ccdb863797e0d32aba93b19249109fbf0 /Command | |
parent | a33ccc14c09d51a1604b34a175e7938d37f29abf (diff) |
groupwanted: New command to set the groupwanted preferred content expression.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/GroupWanted.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Command/GroupWanted.hs b/Command/GroupWanted.hs new file mode 100644 index 000000000..859a39c1b --- /dev/null +++ b/Command/GroupWanted.hs @@ -0,0 +1,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 |