diff options
| author | John MacFarlane <[email protected]> | 2022-09-22 09:47:07 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-22 09:47:07 -0700 |
| commit | bd1d923b86edba6e090ba14b1cd17e1e32c727f2 (patch) | |
| tree | d9aa17acc41811a9664815766c72e0f5bf7d239b /pandoc-cli/src | |
| parent | b38292c2346ebea690eada91a5ac1e0addaa3c0b (diff) | |
Split pandoc-server, pandoc-cli into separate packages. (#8309)
This also removes the unnecessary Setup.hs from pandoc.
Cabal does not need this with build-type 'simple'.
Diffstat (limited to 'pandoc-cli/src')
| -rw-r--r-- | pandoc-cli/src/pandoc.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs new file mode 100644 index 000000000..305fc405e --- /dev/null +++ b/pandoc-cli/src/pandoc.hs @@ -0,0 +1,33 @@ +{- | + Module : Main + Copyright : Copyright (C) 2006-2022 John MacFarlane + License : GNU GPL, version 2 or above + + Maintainer : John MacFarlane <jgm@berkeley@edu> + Stability : alpha + Portability : portable + +Parses command-line options and calls the appropriate readers and +writers. +-} +module Main where +import qualified Control.Exception as E +import Text.Pandoc.App (convertWithOpts, defaultOpts, options, parseOptions) +import Text.Pandoc.Error (handleError) +import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app) +import Safe (readDef) +import System.Environment (getProgName, lookupEnv) +import qualified Network.Wai.Handler.CGI as CGI +import qualified Network.Wai.Handler.Warp as Warp +import Network.Wai.Middleware.Timeout (timeout) + +main :: IO () +main = E.handle (handleError . Left) $ do + prg <- getProgName + cgiTimeout <- maybe 2 (readDef 2) <$> lookupEnv "PANDOC_SERVER_TIMEOUT" + case prg of + "pandoc-server.cgi" -> CGI.run (timeout cgiTimeout app) + "pandoc-server" -> do + sopts <- parseServerOpts + Warp.run (serverPort sopts) (timeout (serverTimeout sopts) app) + _ -> parseOptions options defaultOpts >>= convertWithOpts |
