1 -- | This module defines the 'Configuration' type, which is just a
2 -- wrapper around all of the configuration options we accept on the
10 import System.Console.CmdArgs.Default ( Default(..) )
12 import qualified OptionalConfiguration as OC (
13 OptionalConfiguration(..),
16 -- | The main configuration data type. This will be passed to most of
17 -- the important functions once it has been created.
21 database :: Maybe String,
24 password :: Maybe String,
26 username :: Maybe String }
29 -- | A Configuration with all of its fields set to their default
31 instance Default Configuration where
40 -- | Merge a 'Configuration' with an 'OptionalConfiguration'. This is
41 -- more or less the Monoid instance for 'OptionalConfiguration', but
42 -- since the two types are different, we have to repeat ourselves.
43 merge_optional :: Configuration
44 -> OC.OptionalConfiguration
46 merge_optional cfg opt_cfg =
48 (OC.merge_maybes (database cfg) (OC.database opt_cfg))
49 (merge (detail cfg) (OC.detail opt_cfg))
50 (OC.merge_maybes (host cfg) (OC.host opt_cfg))
51 (OC.merge_maybes (password cfg) (OC.password opt_cfg))
52 (OC.merge_maybes (port cfg) (OC.port opt_cfg))
53 (OC.merge_maybes (username cfg) (OC.username opt_cfg))
55 -- | If the thing on the right is Just something, return that
56 -- something, otherwise return the thing on the left.
57 merge :: a -> Maybe a -> a