diff options
Diffstat (limited to 'Types/DeferredParse.hs')
-rw-r--r-- | Types/DeferredParse.hs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Types/DeferredParse.hs b/Types/DeferredParse.hs index 2f463de35..4b5ee6d59 100644 --- a/Types/DeferredParse.hs +++ b/Types/DeferredParse.hs @@ -12,6 +12,8 @@ module Types.DeferredParse where import Annex import Common +import Options.Applicative.Types + -- Some values cannot be fully parsed without performing an action. -- The action may be expensive, so it's best to call finishParse on such a -- value before using getParsed repeatedly. @@ -31,3 +33,18 @@ instance DeferredParseClass (DeferredParse a) where instance DeferredParseClass (Maybe (DeferredParse a)) where finishParse Nothing = pure Nothing finishParse (Just v) = Just <$> finishParse v + +instance DeferredParseClass [DeferredParse a] where + finishParse v = mapM finishParse v + +-- Use when the Annex action modifies Annex state. +type GlobalSetter = DeferredParse () + +globalOpt :: Annex () -> Parser Bool -> Parser GlobalSetter +globalOpt setter parser = go <$> parser + where + go False = ReadyParse () + go True = DeferredParse setter + +globalSetter :: (v -> Annex ()) -> Parser v -> Parser GlobalSetter +globalSetter setter parser = DeferredParse . setter <$> parser |