summaryrefslogtreecommitdiff
path: root/Propellor/Engine.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-10 17:22:32 -0400
committerJoey Hess2014-04-10 17:23:43 -0400
commit25942fb0cca0ca90933026bf959506e099ff95a4 (patch)
tree2f84378c71abaa4458c5078e8cb8e6726bffbefd /Propellor/Engine.hs
parent5acaf8758f752574140dd79de7996d91a81d1cd4 (diff)
Propellor monad is a Reader for HostAttr
So far, the hostname is only used to improve a message in withPrivData, but I anticipate using HostAttr for a lot more.
Diffstat (limited to 'Propellor/Engine.hs')
-rw-r--r--Propellor/Engine.hs23
1 files changed, 15 insertions, 8 deletions
diff --git a/Propellor/Engine.hs b/Propellor/Engine.hs
index 1ae224ca..c527dc38 100644
--- a/Propellor/Engine.hs
+++ b/Propellor/Engine.hs
@@ -1,30 +1,37 @@
+{-# LANGUAGE PackageImports #-}
+
module Propellor.Engine where
import System.Exit
import System.IO
import Data.Monoid
import System.Console.ANSI
+import "mtl" Control.Monad.Reader
import Propellor.Types
import Propellor.Message
-import Utility.Exception
+import Propellor.Exception
-ensureProperty :: Property -> IO Result
-ensureProperty = catchDefaultIO FailedChange . propertySatisfy
+runPropellor :: HostAttr -> Propellor a -> IO a
+runPropellor hostattr a = runReaderT (runWithHostAttr a) hostattr
-ensureProperties :: [Property] -> IO ()
-ensureProperties ps = do
- r <- ensureProperties' [Property "overall" $ ensureProperties' ps]
+mainProperties :: HostAttr -> [Property] -> IO ()
+mainProperties hostattr ps = do
+ r <- runPropellor hostattr $
+ ensureProperties [Property "overall" $ ensureProperties ps]
setTitle "propellor: done"
hFlush stdout
case r of
FailedChange -> exitWith (ExitFailure 1)
_ -> exitWith ExitSuccess
-ensureProperties' :: [Property] -> IO Result
-ensureProperties' ps = ensure ps NoChange
+ensureProperties :: [Property] -> Propellor Result
+ensureProperties ps = ensure ps NoChange
where
ensure [] rs = return rs
ensure (l:ls) rs = do
r <- actionMessage (propertyDesc l) (ensureProperty l)
ensure ls (r <> rs)
+
+ensureProperty :: Property -> Propellor Result
+ensureProperty = catchPropellor . propertySatisfy