1 {-# LANGUAGE DeriveDataTypeable #-}
3 -- | A newtype around a list of Strings which represent the usernames
4 -- to watch. This is all to avoid an orphan instance of Configured
5 -- for [String] if we had defined one in e.g. OptionalConfiguration.
7 module Usernames ( Usernames(..) )
10 -- DC is needed only for the DCT.Configured instance of String.
11 import qualified Data.Configurator as DC()
12 import qualified Data.Configurator.Types as DCT
13 import Data.Data ( Data )
14 import Data.Monoid ( Monoid(..) )
15 import Data.Typeable ( Typeable )
16 import System.Console.CmdArgs.Default ( Default(..) )
19 -- | Wrapper around a list of strings (usernames).
22 Usernames { get_usernames :: [String] }
23 deriving (Data, Show, Typeable)
26 instance Default Usernames where
27 -- | The default list of usernames is empty.
32 -- | The 'Monoid' instance for 'Usernames' uses an
33 -- 'Monoid' instance for lists.
35 instance Monoid Usernames where
36 -- | The \"empty\" 'Usernames' simply wraps an empty list.
39 -- | This mappend is a little funny; it always chooses the second
40 -- list if that list is nonempty. Otherwise, it chooses the
41 -- first. This is actually associative!
43 | null (get_usernames u2) = u1
47 instance DCT.Configured Usernames where
48 -- | This allows us to read a 'Usernames' object out of a
49 -- Configurator config file. By default Configurator wouldn't know
50 -- what to do, so we have to tell it that we expect a list, and if
51 -- that list has strings in it, we can apply the Usernames
53 convert (DCT.List xs) =
54 fmap Usernames (mapM convert_string xs)
56 convert_string :: DCT.Value -> Maybe String
57 convert_string = DCT.convert