diff options
| author | Joey Hess <joeyh@joeyh.name> | 2014-12-07 18:49:43 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2014-12-07 18:49:43 -0400 |
| commit | 21d87341ca75dcc7f33b87c8725738511f224311 (patch) | |
| tree | d8aaf17b719888c2dbdf838073151b493320876c /src/Propellor/Engine.hs | |
| parent | 19a1d6b7ed29aecf1ff3313eac9f07bf762d1dc6 (diff) | |
| parent | 42a0c832483296fb111279fc3512a3dfd44f2089 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Engine.hs')
| -rw-r--r-- | src/Propellor/Engine.hs | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs index 44b10cab..dc8b2bc5 100644 --- a/src/Propellor/Engine.hs +++ b/src/Propellor/Engine.hs @@ -1,6 +1,14 @@ {-# LANGUAGE PackageImports #-} -module Propellor.Engine where +module Propellor.Engine ( + mainProperties, + runPropellor, + ensureProperty, + ensureProperties, + fromHost, + onlyProcess, + processChainOutput, +) where import System.Exit import System.IO @@ -15,6 +23,7 @@ import System.FilePath import System.Directory import Propellor.Types +import Propellor.Types.Empty import Propellor.Message import Propellor.Exception import Propellor.Info @@ -27,7 +36,7 @@ import Utility.Monad mainProperties :: Host -> IO () mainProperties host = do ret <- runPropellor host $ - ensureProperties [Property "overall" (ensureProperties $ hostProperties host) mempty] + ensureProperties [Property "overall" (ensurePropertiesWith ensureProperty' $ hostProperties host) mempty] h <- mkMessageHandle whenConsole h $ setTitle "propellor: done" @@ -52,21 +61,34 @@ runEndAction host res (EndAction desc a) = actionMessageOn (hostName host) desc (ret, _s, _) <- runRWST (runWithHost (catchPropellor (a res))) host () return ret +-- | For when code running in the Propellor monad needs to ensure a +-- Property. +-- +-- Note that any info of the Property is not propigated out to +-- the enclosing Property, and so will not be available for propellor to +-- use. A warning message will be printed if this is detected. +ensureProperty :: Property -> Propellor Result +ensureProperty p = do + unless (isEmpty (getInfo p)) $ + warningMessage $ "ensureProperty called on " ++ show p ++ "; will not propigate its info: " ++ show (getInfo p) + ensureProperty' p + +ensureProperty' :: Property -> Propellor Result +ensureProperty' = catchPropellor . propertySatisfy + -- | Ensures a list of Properties, with a display of each as it runs. ensureProperties :: [Property] -> Propellor Result -ensureProperties ps = ensure ps NoChange +ensureProperties = ensurePropertiesWith ensureProperty + +ensurePropertiesWith :: (Property -> Propellor Result) -> [Property] -> Propellor Result +ensurePropertiesWith a ps = ensure ps NoChange where ensure [] rs = return rs - ensure (l:ls) rs = do + ensure (p:ls) rs = do hn <- asks hostName - r <- actionMessageOn hn (propertyDesc l) (ensureProperty l) + r <- actionMessageOn hn (propertyDesc p) (a p) ensure ls (r <> rs) --- | For when code running in the Propellor monad needs to ensure a --- Property. -ensureProperty :: Property -> Propellor Result -ensureProperty = catchPropellor . propertySatisfy - -- | Lifts an action into a different host. -- -- For example, `fromHost hosts "otherhost" getSshPubKey` |
