diff options
| author | Joey Hess <joey@kitenet.net> | 2014-11-20 00:58:51 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-11-20 00:58:51 -0400 |
| commit | 02b8b2dec7c767ba3b7154e424b9c11e6a8d544f (patch) | |
| tree | 84f8394029d0b17de94a47ea59dd29b70d5bab38 /src/Propellor/Property.hs | |
| parent | f1b2df601e0eb2fdd5dbc3bc72df0f0493230046 (diff) | |
| parent | 0d4dd37ee769a6ef1bc80507c8ee8a4b9e882856 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Property.hs')
| -rw-r--r-- | src/Propellor/Property.hs | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/Propellor/Property.hs b/src/Propellor/Property.hs index 4b957317..bf69ff60 100644 --- a/src/Propellor/Property.hs +++ b/src/Propellor/Property.hs @@ -89,6 +89,15 @@ check c p = adjustProperty p $ \satisfy -> ifM (liftIO c) , return NoChange ) +-- | Tries the first property, but if it fails to work, instead uses +-- the second. +fallback :: Property -> Property -> Property +fallback p1 p2 = adjustProperty p1 $ \satisfy -> do + r <- satisfy + if r == FailedChange + then propertySatisfy p2 + else return r + -- | Marks a Property as trivial. It can only return FailedChange or -- NoChange. -- @@ -122,6 +131,10 @@ boolProperty desc a = property desc $ ifM (liftIO a) revert :: RevertableProperty -> RevertableProperty revert (RevertableProperty p1 p2) = RevertableProperty p2 p1 +-- | Turns a revertable property into a regular property. +unrevertable :: RevertableProperty -> Property +unrevertable (RevertableProperty p1 _p2) = p1 + -- | Starts accumulating the properties of a Host. -- -- > host "example.com" @@ -131,27 +144,28 @@ revert (RevertableProperty p1 p2) = RevertableProperty p2 p1 host :: HostName -> Host host hn = Host hn [] mempty --- | Adds a property to a Host --- --- Can add Properties and RevertableProperties -(&) :: IsProp p => Host -> p -> Host -(Host hn ps is) & p = Host hn (ps ++ [toProp p]) (is <> getInfo p) +class Hostlike h where + -- | Adds a property to a Host + -- + -- Can add Properties and RevertableProperties + (&) :: IsProp p => h -> p -> h + -- | Like (&), but adds the property as the + -- first property of the host. Normally, property + -- order should not matter, but this is useful + -- when it does. + (&^) :: IsProp p => h -> p -> h -infixl 1 & +instance Hostlike Host where + (Host hn ps is) & p = Host hn (ps ++ [toProp p]) (is <> getInfo p) + (Host hn ps is) &^ p = Host hn ([toProp p] ++ ps) (getInfo p <> is) -- | Adds a property to the Host in reverted form. -(!) :: Host -> RevertableProperty -> Host +(!) :: Hostlike h => h -> RevertableProperty -> h h ! p = h & revert p -infixl 1 ! - --- | Like (&), but adds the property as the first property of the host. --- Normally, property order should not matter, but this is useful --- when it does. -(&^) :: IsProp p => Host -> p -> Host -(Host hn ps is) &^ p = Host hn ([toProp p] ++ ps) (getInfo p <> is) - infixl 1 &^ +infixl 1 & +infixl 1 ! -- Changes the action that is performed to satisfy a property. adjustProperty :: Property -> (Propellor Result -> Propellor Result) -> Property |
