{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DataKinds #-}
module Propellor.PropAccum
( host
, Props(..)
, props
, (&)
, (&^)
, (!)
) where
import Propellor.Types
import Propellor.Types.MetaTypes
import Propellor.Types.Core
import Propellor.Property
import GHC.TypeLits
import Data.Monoid
import Prelude
host :: HostName -> Props metatypes -> Host
host :: HostName -> Props metatypes -> Host
host HostName
hn (Props [ChildProperty]
ps) = HostName -> [ChildProperty] -> Info -> Host
Host HostName
hn [ChildProperty]
ps ([Info] -> Info
forall a. Monoid a => [a] -> a
mconcat ((ChildProperty -> Info) -> [ChildProperty] -> [Info]
forall a b. (a -> b) -> [a] -> [b]
map ChildProperty -> Info
forall p. IsProp p => p -> Info
getInfoRecursive [ChildProperty]
ps))
props :: Props UnixLike
props :: Props UnixLike
props = [ChildProperty] -> Props UnixLike
forall metatypes. [ChildProperty] -> Props metatypes
Props []
infixl 1 &
infixl 1 &^
infixl 1 !
type family GetMetaTypes x where
GetMetaTypes (Property (MetaTypes t)) = MetaTypes t
GetMetaTypes (RevertableProperty (MetaTypes t) undo) = MetaTypes t
type family NoteFor symbol :: ErrorMessage where
NoteFor symbol =
'Text "Probably the problem is with the last property added with "
':<>: symbol
':<>: 'Text " in the code excerpt below."
(&)
::
( IsProp p
, MetaTypes y ~ GetMetaTypes p
, CheckCombinableNote x y (NoteFor ('Text "&"))
)
=> Props (MetaTypes x)
-> p
-> Props (MetaTypes (Combine x y))
Props [ChildProperty]
c & :: Props (MetaTypes x) -> p -> Props (MetaTypes (Combine x y))
& p
p = [ChildProperty]
-> Props
(MetaTypes
(Concat
(Union (NonTargets x) (NonTargets y))
(Intersect (Targets x) (Targets y))))
forall metatypes. [ChildProperty] -> Props metatypes
Props ([ChildProperty]
c [ChildProperty] -> [ChildProperty] -> [ChildProperty]
forall a. [a] -> [a] -> [a]
++ [p -> ChildProperty
forall p. IsProp p => p -> ChildProperty
toChildProperty p
p])
(&^)
::
( IsProp p
, MetaTypes y ~ GetMetaTypes p
, CheckCombinableNote x y (NoteFor ('Text "&^"))
)
=> Props (MetaTypes x)
-> p
-> Props (MetaTypes (Combine x y))
Props [ChildProperty]
c &^ :: Props (MetaTypes x) -> p -> Props (MetaTypes (Combine x y))
&^ p
p = [ChildProperty]
-> Props
(MetaTypes
(Concat
(Union (NonTargets x) (NonTargets y))
(Intersect (Targets x) (Targets y))))
forall metatypes. [ChildProperty] -> Props metatypes
Props (p -> ChildProperty
forall p. IsProp p => p -> ChildProperty
toChildProperty p
p ChildProperty -> [ChildProperty] -> [ChildProperty]
forall a. a -> [a] -> [a]
: [ChildProperty]
c)
(!)
:: CheckCombinableNote x z (NoteFor ('Text "!"))
=> Props (MetaTypes x)
-> RevertableProperty (MetaTypes y) (MetaTypes z)
-> Props (MetaTypes (Combine x z))
Props [ChildProperty]
c ! :: Props (MetaTypes x)
-> RevertableProperty (MetaTypes y) (MetaTypes z)
-> Props (MetaTypes (Combine x z))
! RevertableProperty (MetaTypes y) (MetaTypes z)
p = [ChildProperty]
-> Props
(MetaTypes
(Concat
(Union (NonTargets x) (NonTargets z))
(Intersect (Targets x) (Targets z))))
forall metatypes. [ChildProperty] -> Props metatypes
Props ([ChildProperty]
c [ChildProperty] -> [ChildProperty] -> [ChildProperty]
forall a. [a] -> [a] -> [a]
++ [RevertableProperty (MetaTypes z) (MetaTypes y) -> ChildProperty
forall p. IsProp p => p -> ChildProperty
toChildProperty (RevertableProperty (MetaTypes y) (MetaTypes z)
-> RevertableProperty (MetaTypes z) (MetaTypes y)
forall setup undo.
RevertableProperty setup undo -> RevertableProperty undo setup
revert RevertableProperty (MetaTypes y) (MetaTypes z)
p)])