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 System.Console.CmdArgs.Default ( Default(..) )
15 import Data.Typeable ( Typeable )
18 -- | Wrapper around a list of strings (usernames).
21 Usernames { get_usernames :: [String] }
22 deriving (Data, Show, Typeable)
25 instance Default Usernames where
26 -- | The default list of usernames is empty.
32 instance DCT.Configured Usernames where
33 -- | This allows us to read a 'Usernames' object out of a
34 -- Configurator config file. By default Configurator wouldn't know
35 -- what to do, so we have to tell it that we expect a list, and if
36 -- that list has strings in it, we can apply the Usernames
38 convert (DCT.List xs) =
39 fmap Usernames (mapM convert_string xs)
41 convert_string :: DCT.Value -> Maybe String
42 convert_string = DCT.convert