diff options
| author | Joey Hess <joey@kitenet.net> | 2014-05-14 19:47:17 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-05-14 19:47:17 -0400 |
| commit | 39217c55690de5641a9fe4ef2236d6127ebbcbb3 (patch) | |
| tree | 31284fd462e2d02cf9bf0b8077c0e8dd34181988 /src/Propellor/Engine.hs | |
| parent | eb6e6fe11290971b37a18d9a78f6d9b78228c06f (diff) | |
| parent | 7115d1ec162b4059b3e8e8f84bd8d5898c1db025 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Engine.hs')
| -rw-r--r-- | src/Propellor/Engine.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs new file mode 100644 index 00000000..55ce7f77 --- /dev/null +++ b/src/Propellor/Engine.hs @@ -0,0 +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 Propellor.Exception + +runPropellor :: Attr -> Propellor a -> IO a +runPropellor attr a = runReaderT (runWithAttr a) attr + +mainProperties :: Attr -> [Property] -> IO () +mainProperties attr ps = do + r <- runPropellor attr $ + ensureProperties [Property "overall" (ensureProperties ps) id] + setTitle "propellor: done" + hFlush stdout + case r of + FailedChange -> exitWith (ExitFailure 1) + _ -> exitWith ExitSuccess + +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 |
