From 7c4b1537391d801855e28a61c896efcc70cfaa81 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 31 May 2014 21:18:36 -0400 Subject: simplify monoid instance with some helper types --- src/Propellor/Attr.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Propellor/Attr.hs') diff --git a/src/Propellor/Attr.hs b/src/Propellor/Attr.hs index 29d7a01e..3ed59437 100644 --- a/src/Propellor/Attr.hs +++ b/src/Propellor/Attr.hs @@ -15,12 +15,15 @@ import Control.Applicative pureAttrProperty :: Desc -> Attr -> Property pureAttrProperty desc = Property ("has " ++ desc) (return NoChange) +askAttr :: (Attr -> Val a) -> Propellor (Maybe a) +askAttr f = asks (fromVal . f . hostAttr) + os :: System -> Property os system = pureAttrProperty ("Operating " ++ show system) $ - mempty { _os = Just system } + mempty { _os = Val system } getOS :: Propellor (Maybe System) -getOS = asks (_os . hostAttr) +getOS = askAttr _os -- | Indidate that a host has an A record in the DNS. -- @@ -55,10 +58,10 @@ addDNS r = pureAttrProperty (rdesc r) $ sshPubKey :: String -> Property sshPubKey k = pureAttrProperty ("ssh pubkey known") $ - mempty { _sshPubKey = Just k } + mempty { _sshPubKey = Val k } getSshPubKey :: Propellor (Maybe String) -getSshPubKey = asks (_sshPubKey . hostAttr) +getSshPubKey = askAttr _sshPubKey hostMap :: [Host] -> M.Map HostName Host hostMap l = M.fromList $ zip (map hostName l) l -- cgit v1.3-2-g0d8e