about summary refs log tree commit diff
path: root/src/GopherProxy/Config.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GopherProxy/Config.hs')
-rw-r--r--src/GopherProxy/Config.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/GopherProxy/Config.hs b/src/GopherProxy/Config.hs
new file mode 100644
index 0000000..ec0b44e
--- /dev/null
+++ b/src/GopherProxy/Config.hs
@@ -0,0 +1,37 @@
+{-# LANGUAGE DeriveGeneric     #-}
+{-# LANGUAGE OverloadedStrings #-}
+module GopherProxy.Config
+  ( Config (..)
+  , dCssUrl
+  , dBaseUrl
+  ) where
+
+import qualified Data.ByteString as BS
+import Data.Maybe (fromMaybe)
+import Network.Socket (HostName (), PortNumber ())
+import Options.Applicative.Types
+import Options.Generic
+
+data Config
+  = Config
+    { hostname     :: HostName
+    , port         :: PortNumber
+    , httpPort     :: Int
+    , cssPath      :: FilePath
+    , cssUrl       :: Maybe BS.ByteString
+    , baseUrl      :: Maybe Text
+    } deriving (Generic, Show)
+
+instance ParseRecord PortNumber where
+  parseRecord = fmap getOnly parseRecord
+
+instance ParseFields PortNumber where
+  parseFields a b = fmap fromIntegral (parseFields a b :: Parser Integer)
+
+instance ParseRecord Config
+
+dCssUrl :: Config -> BS.ByteString
+dCssUrl = fromMaybe "/gopher-proxy.css" . cssUrl
+
+dBaseUrl :: Config -> Text
+dBaseUrl = fromMaybe "/" . baseUrl