summaryrefslogtreecommitdiff
path: root/Propellor/PrivData.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-10 17:22:32 -0400
committerJoey Hess2014-04-10 17:23:43 -0400
commit25942fb0cca0ca90933026bf959506e099ff95a4 (patch)
tree2f84378c71abaa4458c5078e8cb8e6726bffbefd /Propellor/PrivData.hs
parent5acaf8758f752574140dd79de7996d91a81d1cd4 (diff)
Propellor monad is a Reader for HostAttr
So far, the hostname is only used to improve a message in withPrivData, but I anticipate using HostAttr for a lot more.
Diffstat (limited to 'Propellor/PrivData.hs')
-rw-r--r--Propellor/PrivData.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/Propellor/PrivData.hs b/Propellor/PrivData.hs
index 2897d425..7f5a23dc 100644
--- a/Propellor/PrivData.hs
+++ b/Propellor/PrivData.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE PackageImports #-}
+
module Propellor.PrivData where
import qualified Data.Map as M
@@ -7,6 +9,7 @@ import System.IO
import System.Directory
import Data.Maybe
import Control.Monad
+import "mtl" Control.Monad.Reader
import Propellor.Types
import Propellor.Message
@@ -18,13 +21,15 @@ import Utility.Tmp
import Utility.SafeCommand
import Utility.Misc
-withPrivData :: PrivDataField -> (String -> IO Result) -> IO Result
-withPrivData field a = maybe missing a =<< getPrivData field
+withPrivData :: PrivDataField -> (String -> Propellor Result) -> Propellor Result
+withPrivData field a = maybe missing a =<< liftIO (getPrivData field)
where
missing = do
- warningMessage $ "Missing privdata " ++ show field
- putStrLn $ "Fix this by running: propellor --set $hostname '" ++ show field ++ "'"
- return FailedChange
+ host <- getHostName
+ liftIO $ do
+ warningMessage $ "Missing privdata " ++ show field
+ putStrLn $ "Fix this by running: propellor --set "++host++" '" ++ show field ++ "'"
+ return FailedChange
getPrivData :: PrivDataField -> IO (Maybe String)
getPrivData field = do