83bf7c3492b22d5a2a333dc001ebfc9a36a67ad2
[dead/harbl.git] / harbl-cli / src / Hosts.hs
1 -- | A newtype around a list of Strings which represent hosts to look up.
2 -- This is all to avoid an orphan instance of 'Configured' for
3 -- [String] if we had defined one in e.g. 'OptionalConfiguration'.
4 --
5 {-# LANGUAGE DeriveDataTypeable #-}
6 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
7
8 module Hosts ( Hosts(..) )
9 where
10
11 import Data.Configurator () -- Needed for predefined instances.
12 import Data.Configurator.Types ( Configured(..) )
13 import Data.Monoid ( Monoid )
14 import Data.Data ( Data )
15 import System.Console.CmdArgs.Default ( Default(..) )
16 import Data.Typeable ( Typeable )
17
18 import Configurator ( convert_newtype_list )
19
20
21 -- | A (wrapper around a) list of hosts.
22 --
23 newtype Hosts =
24 Hosts { get_hosts :: [String] }
25 deriving (Data, Monoid, Show, Typeable)
26
27
28 -- | The default list of hosts. It's empty.
29 --
30 instance Default Hosts where def = Hosts []
31
32 instance Configured Hosts where
33 -- | This allows us to read a Hosts object out of a Configurator
34 -- config file: by default Configurator wouldn't know what to do.
35 convert = convert_newtype_list Hosts