summaryrefslogtreecommitdiff
path: root/src/Propellor/Engine.hs
diff options
context:
space:
mode:
authorJoey Hess2014-05-31 18:02:56 -0400
committerJoey Hess2014-05-31 18:04:41 -0400
commit5fc4b006517051e937cbfa13b5f7ccbc25460c1b (patch)
treef99b7dcf46d262f13aa80fb39c8fcc1a67c951a9 /src/Propellor/Engine.hs
parentd3ac75a1a29e9eda60b78d25e7352d4a2d5713cc (diff)
remove now redundant _hostname field of Attr
Now that Host includes _hostName, it's redundant to also keep it in Attr. This requires changing the reader monad to operate on the whole Host.
Diffstat (limited to 'src/Propellor/Engine.hs')
-rw-r--r--src/Propellor/Engine.hs23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/Propellor/Engine.hs b/src/Propellor/Engine.hs
index 55ce7f77..9bb3531a 100644
--- a/src/Propellor/Engine.hs
+++ b/src/Propellor/Engine.hs
@@ -5,20 +5,22 @@ module Propellor.Engine where
import System.Exit
import System.IO
import Data.Monoid
+import Control.Applicative
import System.Console.ANSI
import "mtl" Control.Monad.Reader
import Propellor.Types
import Propellor.Message
import Propellor.Exception
+import Propellor.Attr
-runPropellor :: Attr -> Propellor a -> IO a
-runPropellor attr a = runReaderT (runWithAttr a) attr
+runPropellor :: Host -> Propellor a -> IO a
+runPropellor host a = runReaderT (runWithHost a) host
-mainProperties :: Attr -> [Property] -> IO ()
-mainProperties attr ps = do
- r <- runPropellor attr $
- ensureProperties [Property "overall" (ensureProperties ps) id]
+mainProperties :: Host -> IO ()
+mainProperties host = do
+ r <- runPropellor host $
+ ensureProperties [Property "overall" (ensureProperties $ hostProperties host) id]
setTitle "propellor: done"
hFlush stdout
case r of
@@ -35,3 +37,12 @@ ensureProperties ps = ensure ps NoChange
ensureProperty :: Property -> Propellor Result
ensureProperty = catchPropellor . propertySatisfy
+
+-- | Lifts an action into a different host.
+--
+-- For example, `fromHost hosts "otherhost" getSshPubKey`
+fromHost :: [Host] -> HostName -> Propellor a -> Propellor (Maybe a)
+fromHost l hn getter = case findHost l hn of
+ Nothing -> return Nothing
+ Just h -> liftIO $ Just <$>
+ runReaderT (runWithHost getter) h