X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fharbl.git;a=blobdiff_plain;f=harbl-cli%2Fsrc%2FHosts.hs;h=83bf7c3492b22d5a2a333dc001ebfc9a36a67ad2;hp=020484dff1dc1872fe6e742d61fd6c2121fcacfb;hb=b47aaa60a797aee4ecdcd5535ed40c1a7b15ddce;hpb=6eb7fe0f53b0d8690a821cce9257b8b1a17fdaad diff --git a/harbl-cli/src/Hosts.hs b/harbl-cli/src/Hosts.hs index 020484d..83bf7c3 100644 --- a/harbl-cli/src/Hosts.hs +++ b/harbl-cli/src/Hosts.hs @@ -3,45 +3,33 @@ -- [String] if we had defined one in e.g. 'OptionalConfiguration'. -- {-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Hosts ( Hosts(..) ) where --- DC is needed only for the DCT.Configured instance of String. -import qualified Data.Configurator as DC() -import qualified Data.Configurator.Types as DCT ( - Configured, - Value( List ), - convert ) +import Data.Configurator () -- Needed for predefined instances. +import Data.Configurator.Types ( Configured(..) ) +import Data.Monoid ( Monoid ) import Data.Data ( Data ) import System.Console.CmdArgs.Default ( Default(..) ) import Data.Typeable ( Typeable ) +import Configurator ( convert_newtype_list ) + -- | A (wrapper around a) list of hosts. -- newtype Hosts = Hosts { get_hosts :: [String] } - deriving (Data, Show, Typeable) + deriving (Data, Monoid, Show, Typeable) -- | The default list of hosts. It's empty. -- instance Default Hosts where def = Hosts [] -instance DCT.Configured Hosts where +instance Configured Hosts where -- | This allows us to read a Hosts object out of a Configurator - -- config file. By default Configurator wouldn't know what to do, - -- so we have to tell it that we expect a list, and if that list - -- has strings in it, we can apply the Hosts constructor to - -- it. - convert (DCT.List xs) = - -- mapM gives us a Maybe [String] here. - fmap Hosts (mapM convert_string xs) - where - convert_string :: DCT.Value -> Maybe String - convert_string = DCT.convert - - -- If we read anything other than a list of values out of the file, - -- fail. - convert _ = Nothing + -- config file: by default Configurator wouldn't know what to do. + convert = convert_newtype_list Hosts