diff options
| author | Joey Hess <joey@kitenet.net> | 2014-05-31 21:18:36 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-05-31 21:18:36 -0400 |
| commit | 7c4b1537391d801855e28a61c896efcc70cfaa81 (patch) | |
| tree | 010b433c4f9eae6f0336ad0735f2893cf0a7498e /src/Propellor/Attr.hs | |
| parent | d1eafb12776d6487ecd48d3991838032a81181d6 (diff) | |
simplify monoid instance with some helper types
Diffstat (limited to 'src/Propellor/Attr.hs')
| -rw-r--r-- | src/Propellor/Attr.hs | 11 |
1 files changed, 7 insertions, 4 deletions
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 |
