]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Usernames.hs
6aec228ed06397873a3dc496afcf221f5dc9a19c
[dead/halcyon.git] / src / Usernames.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
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.
6 --
7 module Usernames ( Usernames(..) )
8 where
9
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 )
16
17
18 -- | Wrapper around a list of strings (usernames).
19 --
20 newtype Usernames =
21 Usernames { get_usernames :: [String] }
22 deriving (Data, Show, Typeable)
23
24
25 instance Default Usernames where
26 -- | The default list of usernames is empty.
27 --
28 def = Usernames []
29
30
31
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
37 -- constructor to it.
38 convert (DCT.List xs) =
39 fmap Usernames (mapM convert_string xs)
40 where
41 convert_string :: DCT.Value -> Maybe String
42 convert_string = DCT.convert
43
44 convert _ = Nothing