summaryrefslogtreecommitdiff
path: root/src/Propellor/Engine.hs
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2014-11-20 19:21:22 -0400
committerJoey Hess <joey@kitenet.net>2014-11-20 19:21:22 -0400
commit1eaeddc2ebc5af5351b2de3d8a4d1788a77039da (patch)
tree2a7d89097f2392788b1461083f0aa1c617950d90 /src/Propellor/Engine.hs
parent02b8b2dec7c767ba3b7154e424b9c11e6a8d544f (diff)
parentba862ae8877c21eb63f7fba08ba5fc934a4c391c (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Engine.hs')
-rw-r--r--src/Propellor/Engine.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs
index 3fa9ffc0..969769ce 100644
--- a/src/Propellor/Engine.hs
+++ b/src/Propellor/Engine.hs
@@ -11,12 +11,15 @@ import "mtl" Control.Monad.Reader
import Control.Exception (bracket)
import System.PosixCompat
import System.Posix.IO
+import Data.Maybe
import Propellor.Types
import Propellor.Message
import Propellor.Exception
import Propellor.Info
import Utility.Exception
+import Utility.PartialPrelude
+import Utility.Monad
runPropellor :: Host -> Propellor a -> IO a
runPropellor host a = runReaderT (runWithHost a) host
@@ -62,3 +65,18 @@ onlyProcess lockfile a = bracket lock unlock (const a)
return l
unlock = closeFd
alreadyrunning = error "Propellor is already running on this host!"
+
+-- | Reads and displays each line from the Handle, except for the last line
+-- which is a Result.
+processChainOutput :: Handle -> IO Result
+processChainOutput h = go Nothing
+ where
+ go lastline = do
+ v <- catchMaybeIO (hGetLine h)
+ case v of
+ Nothing -> pure $ fromMaybe FailedChange $
+ readish =<< lastline
+ Just s -> do
+ maybe noop (\l -> unless (null l) (putStrLn l)) lastline
+ hFlush stdout
+ go (Just s)