]> gitweb.michael.orlitzky.com - list-remote-forwards.git/blobdiff - src/OptionalConfiguration.hs
list-remote-forwards.cabal: delete the redundant description
[list-remote-forwards.git] / src / OptionalConfiguration.hs
index 072f25beafc4cfd3ffd1b3b4e0c62e43edaa9943..bfd4da755302e87dd74aa427ff286827468e464b 100644 (file)
@@ -20,15 +20,13 @@ import qualified Data.Configurator as DC (
   lookup )
 
 import Data.Maybe ( fromMaybe )
-import Data.Monoid ( Monoid(..) )
 import Data.Data ( Data )
-import Data.Typeable ( Typeable )
 import Paths_list_remote_forwards ( getSysconfDir )
 import System.Directory ( getHomeDirectory )
 import System.FilePath ( (</>) )
 import System.IO.Error ( catchIOError )
 
-import MxList ( MxList(..) )
+import MxList ( MxList(MxList, get_mxs) )
 
 -- | The same as Configuration, except everything is optional. It's easy to
 --   merge two of these by simply dropping the Nothings in favor of
@@ -45,7 +43,7 @@ data OptionalConfiguration =
     password :: Maybe String,
     port     :: Maybe Int,
     username :: Maybe String }
-  deriving (Show, Data, Typeable)
+  deriving (Show, Data)
 
 
 -- | Combine two Maybes into one, essentially mashing them
@@ -58,7 +56,7 @@ merge_maybes Nothing (Just x)  = Just x
 merge_maybes (Just _) (Just y) = Just y
 
 
--- | The Monoid instance for these lets us "combine" two
+-- | The Semigroup instance for these lets us "combine" two
 --   OptionalConfigurations. The "combine" operation that we'd like to
 --   perform is, essentially, to mash them together. So if we have two
 --   OptionalConfigurations, each half full, we could combine them
@@ -66,20 +64,10 @@ merge_maybes (Just _) (Just y) = Just y
 --
 --   This is used to merge command-line and config-file settings.
 --
-instance Monoid OptionalConfiguration where
-  -- | An empty OptionalConfiguration.
-  mempty = OptionalConfiguration
-             Nothing
-             Nothing
-             (MxList [])
-             Nothing
-             Nothing
-             Nothing
-             Nothing
-             Nothing
 
+instance Semigroup OptionalConfiguration where
   -- | Combine @cfg1@ and @cfg2@, giving precedence to @cfg2@.
-  cfg1 `mappend` cfg2 =
+  cfg1 <> cfg2 =
     OptionalConfiguration
       (merge_maybes (database cfg1) (database cfg2))
       (merge_maybes (domain_query cfg1) (domain_query cfg2))
@@ -96,6 +84,21 @@ instance Monoid OptionalConfiguration where
                      then cfg1
                      else cfg2
 
+-- | The Monoid instance essentially only provides the "empty
+--   configuration."
+instance Monoid OptionalConfiguration where
+  -- | An empty OptionalConfiguration.
+  mempty = OptionalConfiguration
+             Nothing
+             Nothing
+             (MxList [])
+             Nothing
+             Nothing
+             Nothing
+             Nothing
+             Nothing
+  mappend = (<>)
+
 
 -- | Obtain an OptionalConfiguration from list-remote-forwardsrc in
 --   either the global configuration directory or the user's home