diff options
| author | Joey Hess <joey@kitenet.net> | 2014-03-31 01:06:44 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-03-31 01:06:44 -0400 |
| commit | 9d348647d9d1b47d0119b3988e0ece9aa383d166 (patch) | |
| tree | 395083db20bd8e8508a730af7d8ca031f6f79ca3 /Propellor | |
| parent | 2383674638d14b18a668fa2fcd2689724b4ae4cc (diff) | |
propellor spin
Diffstat (limited to 'Propellor')
| -rw-r--r-- | Propellor/Engine.hs | 47 | ||||
| -rw-r--r-- | Propellor/PrivData.hs | 2 | ||||
| -rw-r--r-- | Propellor/Property.hs | 44 |
3 files changed, 49 insertions, 44 deletions
diff --git a/Propellor/Engine.hs b/Propellor/Engine.hs new file mode 100644 index 00000000..e5f8a965 --- /dev/null +++ b/Propellor/Engine.hs @@ -0,0 +1,47 @@ +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] + 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 + 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 [] + ensure ls (combineResult r rs) + +warningMessage :: String -> IO () +warningMessage s = do + setSGR [SetColor Foreground Vivid Red] + putStrLn $ "** warning: " ++ s + setSGR [] + hFlush stdout diff --git a/Propellor/PrivData.hs b/Propellor/PrivData.hs index 27b3f77f..5f0de3b0 100644 --- a/Propellor/PrivData.hs +++ b/Propellor/PrivData.hs @@ -9,7 +9,7 @@ import Data.Maybe import Control.Monad import Propellor.Types -import Propellor.Property +import Propellor.Engine import Utility.Monad import Utility.PartialPrelude import Utility.Exception diff --git a/Propellor/Property.hs b/Propellor/Property.hs index 727fe25e..c2e2cbab 100644 --- a/Propellor/Property.hs +++ b/Propellor/Property.hs @@ -2,13 +2,10 @@ module Propellor.Property where import System.Directory import Control.Monad -import System.Console.ANSI -import System.Exit -import System.IO import Propellor.Types +import Propellor.Engine import Utility.Monad -import Utility.Exception makeChange :: IO () -> IO Result makeChange a = a >> return MadeChange @@ -82,42 +79,3 @@ check c property = Property (propertyDesc property) $ ifM c ( ensureProperty property , return NoChange ) - -ensureProperty :: Property -> IO Result -ensureProperty = catchDefaultIO FailedChange . propertySatisfy - -ensureProperties :: [Property] -> IO () -ensureProperties ps = do - r <- ensureProperties' [propertyList "overall" ps] - 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 - 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 [] - ensure ls (combineResult r rs) - -warningMessage :: String -> IO () -warningMessage s = do - setSGR [SetColor Foreground Vivid Red] - putStrLn $ "** warning: " ++ s - setSGR [] - hFlush stdout |
