propellor/Propellor/Types.hs

40 lines
993 B
Haskell
Raw Normal View History

2014-03-31 03:37:54 +00:00
module Propellor.Types where
2014-03-30 23:10:32 +00:00
2014-03-31 14:36:45 +00:00
import Data.Monoid
2014-03-31 22:31:08 +00:00
import System.Console.ANSI
2014-03-31 14:36:45 +00:00
2014-03-30 23:10:32 +00:00
type HostName = String
type UserName = String
data Property = Property
{ propertyDesc :: Desc
2014-03-31 03:37:54 +00:00
-- | must be idempotent; may run repeatedly
2014-03-30 23:10:32 +00:00
, propertySatisfy :: IO Result
}
type Desc = String
data Result = NoChange | MadeChange | FailedChange
deriving (Show, Eq)
2014-03-31 14:36:45 +00:00
instance Monoid Result where
mempty = NoChange
mappend FailedChange _ = FailedChange
mappend _ FailedChange = FailedChange
mappend MadeChange _ = MadeChange
mappend _ MadeChange = MadeChange
mappend NoChange NoChange = NoChange
2014-03-31 22:31:08 +00:00
class ActionResult a where
getActionResult :: a -> (String, ColorIntensity, Color)
instance ActionResult Bool where
getActionResult False = ("ok", Vivid, Red)
getActionResult True = ("failed", Vivid, Green)
instance ActionResult Result where
getActionResult NoChange = ("unchanged", Dull, Green)
getActionResult MadeChange = ("done", Vivid, Green)
getActionResult FailedChange = ("failed", Vivid, Red)