propellor/Propellor/Engine.hs

53 lines
1.3 KiB
Haskell
Raw Normal View History

2014-03-31 05:06:44 +00:00
module Propellor.Engine where
import System.Console.ANSI
import System.Exit
import System.IO
import Propellor.Types
import Utility.Exception
ensureProperty :: Property -> IO Result
ensureProperty = catchDefaultIO FailedChange . propertySatisfy
ensureProperties :: [Property] -> IO ()
ensureProperties ps = do
r <- ensureProperties' [Property "overall" $ ensureProperties' ps]
2014-03-31 05:19:40 +00:00
setTitle "propellor done"
hFlush stdout
2014-03-31 05:06:44 +00:00
case r of
FailedChange -> exitWith (ExitFailure 1)
_ -> exitWith ExitSuccess
ensureProperties' :: [Property] -> IO Result
ensureProperties' ps = ensure ps NoChange
where
ensure [] rs = return rs
ensure (l:ls) rs = do
2014-03-31 05:10:50 +00:00
setTitle $ propertyDesc l
2014-03-31 05:16:01 +00:00
hFlush stdout
2014-03-31 05:06:44 +00:00
r <- ensureProperty l
clearFromCursorToLineBeginning
setCursorColumn 0
putStr $ propertyDesc l ++ "... "
case r of
FailedChange -> do
setSGR [SetColor Foreground Vivid Red]
putStrLn "failed"
NoChange -> do
setSGR [SetColor Foreground Dull Green]
putStrLn "unchanged"
MadeChange -> do
setSGR [SetColor Foreground Vivid Green]
putStrLn "done"
setSGR []
2014-03-31 05:16:01 +00:00
hFlush stdout
2014-03-31 05:06:44 +00:00
ensure ls (combineResult r rs)
warningMessage :: String -> IO ()
warningMessage s = do
setSGR [SetColor Foreground Vivid Red]
putStrLn $ "** warning: " ++ s
setSGR []
hFlush stdout