2022-08-19 12:58:58 +00:00
|
|
|
{-# Language ApplicativeDo #-}
|
|
|
|
{-# Language RecordWildCards #-}
|
2022-08-13 11:56:09 +00:00
|
|
|
import Gemini
|
2022-08-13 19:12:22 +00:00
|
|
|
import Options.Applicative
|
|
|
|
|
2022-08-19 12:58:58 +00:00
|
|
|
|
2022-08-13 19:12:22 +00:00
|
|
|
data Sample = Sample
|
|
|
|
{ baseDir :: String
|
|
|
|
, language :: String
|
2022-08-19 12:58:58 +00:00
|
|
|
, virtualhost :: Bool
|
2022-08-13 19:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sample :: Parser Sample
|
2022-08-19 12:58:58 +00:00
|
|
|
sample = do
|
|
|
|
baseDir <- strOption
|
2022-08-13 19:12:22 +00:00
|
|
|
( long "baseDir"
|
|
|
|
<> short 'd'
|
|
|
|
<> help "base directory to serve files from"
|
|
|
|
<> value "/var/gemini/")
|
2022-08-19 12:58:58 +00:00
|
|
|
language <- strOption
|
2022-08-13 19:12:22 +00:00
|
|
|
( long "language"
|
|
|
|
<> short 'l'
|
|
|
|
<> help "language to use in the response for gemini files"
|
|
|
|
<> value "")
|
2022-08-19 12:58:58 +00:00
|
|
|
virtualhost <- switch
|
|
|
|
( long "virtualhost"
|
|
|
|
<> short 'v'
|
|
|
|
<> help "virtualhost support")
|
|
|
|
pure Sample{..}
|
2022-08-13 19:12:22 +00:00
|
|
|
|
|
|
|
opts :: ParserInfo Sample
|
|
|
|
opts = info (sample <**> helper)
|
2022-08-19 12:58:58 +00:00
|
|
|
(fullDesc)
|
2022-08-13 11:56:09 +00:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2022-08-13 19:12:22 +00:00
|
|
|
options <- execParser opts
|
2022-08-21 11:16:17 +00:00
|
|
|
request <- get_request
|
2022-08-19 12:58:58 +00:00
|
|
|
answer <- create_answer request (language options) (baseDir options) (virtualhost options)
|
2022-08-17 10:35:44 +00:00
|
|
|
putStr (make_reply answer)
|
|
|
|
putStr (content answer)
|