diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-25 12:44:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-25 12:44:58 -0400 |
commit | b93439ab21727ad809ebce384b78e572799fa39a (patch) | |
tree | a36efdd4adc246cb40a62451d84d4ce66bf38c15 /Command | |
parent | 6442bc73b2799c46c8a45a3cd265dd8dfeaea1f3 (diff) |
content: New command line way to view and configure a repository's preferred content settings.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Content.hs | 48 | ||||
-rw-r--r-- | Command/Group.hs | 2 | ||||
-rw-r--r-- | Command/Vicfg.hs | 6 |
3 files changed, 52 insertions, 4 deletions
diff --git a/Command/Content.hs b/Command/Content.hs new file mode 100644 index 000000000..d10bdde3c --- /dev/null +++ b/Command/Content.hs @@ -0,0 +1,48 @@ +{- git-annex command + - + - Copyright 2013 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.Content where + +import Common.Annex +import Command +import qualified Remote +import Logs.PreferredContent + +import qualified Data.Map as M + +def :: [Command] +def = [command "content" (paramPair paramRemote (paramOptional paramExpression)) seek + SectionSetup "get or set preferred content expression"] + +seek :: [CommandSeek] +seek = [withWords start] + +start :: [String] -> CommandStart +start = parse + where + parse (name:[]) = go name performGet + parse (name:expr:[]) = go name $ \uuid -> do + showStart "content" name + performSet expr uuid + parse _ = error "Specify a repository." + + go name a = do + u <- Remote.nameToUUID name + next $ a u + +performGet :: UUID -> CommandPerform +performGet uuid = do + m <- preferredContentMapRaw + liftIO $ putStrLn $ fromMaybe "" $ M.lookup uuid m + next $ return True + +performSet :: String -> UUID -> CommandPerform +performSet expr uuid = case checkPreferredContentExpression expr of + Just e -> error $ "Parse error: " ++ e + Nothing -> do + preferredContentSet uuid expr + next $ return True diff --git a/Command/Group.hs b/Command/Group.hs index aee02b6c4..4c0bf4899 100644 --- a/Command/Group.hs +++ b/Command/Group.hs @@ -17,7 +17,7 @@ import qualified Data.Set as S def :: [Command] def = [command "group" (paramPair paramRemote paramDesc) seek - SectionCommon "add a repository to a group"] + SectionSetup "add a repository to a group"] seek :: [CommandSeek] seek = [withWords start] diff --git a/Command/Vicfg.hs b/Command/Vicfg.hs index b176e5597..1aa8722c5 100644 --- a/Command/Vicfg.hs +++ b/Command/Vicfg.hs @@ -117,8 +117,8 @@ genCfg cfg descs = unlines $ concat [intro, trust, groups, preferredcontent] [ "" , com "Repository preferred contents" ] - (\(s, u) -> line "preferred-content" u s) - (\u -> line "preferred-content" u "") + (\(s, u) -> line "content" u s) + (\u -> line "content" u "") settings field desc showvals showdefaults = concat [ desc @@ -167,7 +167,7 @@ parseCfg curcfg = go [] curcfg . lines | setting == "group" = let m = M.insert u (S.fromList $ words value) (cfgGroupMap cfg) in Right $ cfg { cfgGroupMap = m } - | setting == "preferred-content" = + | setting == "content" = case checkPreferredContentExpression value of Just e -> Left e Nothing -> |