summaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-06 03:06:25 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-06 03:16:42 -0400
commit0a36f92a31196451c2d838fd0ae15527e8bbce18 (patch)
tree54e2a90339ad3d24dbc3d0599a580db63b25ed32 /Annex.hs
parent2051d804625be0c19e277764ab9820b428a5d2b3 (diff)
more command-specific options
Made --from and --to command-specific options. Added generic storage for values of command-specific options, which allows removing some of the special case fields in AnnexState. (Also added generic storage for command-specific flags, although there are not yet any.) Note that this storage uses a Map, so repeatedly looking up the same value is slightly more expensive than looking up an AnnexState field. But, the value can be looked up once in the seek stage, transformed as necessary, and passed in a closure to the start stage, and this avoids that overhead. Still, I'm hesitant to use this for things like force or fast flags. It's probably best to reserve it for flags that are only used by a few commands, or options like --from and --to that it's important only be allowed to be used with commands that implement them, to avoid user confusion.
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs33
1 files changed, 26 insertions, 7 deletions
diff --git a/Annex.hs b/Annex.hs
index 91d374aec..f1e46126a 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -17,6 +17,10 @@ module Annex (
eval,
getState,
changeState,
+ setFlag,
+ setField,
+ getFlag,
+ getField,
gitRepo,
inRepo,
fromRepo,
@@ -38,7 +42,6 @@ import Types.BranchState
import Types.TrustLevel
import Types.UUID
import qualified Utility.Matcher
-import qualified Utility.Format
import qualified Data.Map as M
-- git-annex's monad
@@ -76,17 +79,16 @@ data AnnexState = AnnexState
, force :: Bool
, fast :: Bool
, auto :: Bool
- , format :: Maybe Utility.Format.Format
, branchstate :: BranchState
, catfilehandle :: Maybe CatFileHandle
, forcebackend :: Maybe String
, forcenumcopies :: Maybe Int
- , toremote :: Maybe String
- , fromremote :: Maybe String
, limit :: Matcher (FilePath -> Annex Bool)
, forcetrust :: [(UUID, TrustLevel)]
, trustmap :: Maybe TrustMap
, ciphers :: M.Map EncryptedCipher Cipher
+ , flags :: M.Map String Bool
+ , fields :: M.Map String String
}
newState :: Git.Repo -> AnnexState
@@ -99,17 +101,16 @@ newState gitrepo = AnnexState
, force = False
, fast = False
, auto = False
- , format = Nothing
, branchstate = startBranchState
, catfilehandle = Nothing
, forcebackend = Nothing
, forcenumcopies = Nothing
- , toremote = Nothing
- , fromremote = Nothing
, limit = Left []
, forcetrust = []
, trustmap = Nothing
, ciphers = M.empty
+ , flags = M.empty
+ , fields = M.empty
}
{- Create and returns an Annex state object for the specified git repo. -}
@@ -134,6 +135,24 @@ getState = gets
changeState :: (AnnexState -> AnnexState) -> Annex ()
changeState = modify
+{- Sets a flag to True -}
+setFlag :: String -> Annex ()
+setFlag flag = changeState $ \s ->
+ s { flags = M.insert flag True $ flags s }
+
+{- Sets a field to a value -}
+setField :: String -> String -> Annex ()
+setField field value = changeState $ \s ->
+ s { fields = M.insert field value $ fields s }
+
+{- Checks if a flag was set. -}
+getFlag :: String -> Annex Bool
+getFlag flag = fromMaybe False . M.lookup flag <$> getState flags
+
+{- Gets the value of a field. -}
+getField :: String -> Annex (Maybe String)
+getField field = M.lookup field <$> getState fields
+
{- Returns the annex's git repository. -}
gitRepo :: Annex Git.Repo
gitRepo = getState repo