aboutsummaryrefslogtreecommitdiff
path: root/pandoc-cli
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-09-27 11:59:52 +0200
committerJohn MacFarlane <[email protected]>2022-09-27 08:42:27 -0700
commit175b791529a960bf7df8bccb8876783076b3d321 (patch)
tree17df31777977ce93e22960b8796c56bde3967e7e /pandoc-cli
parenta3fd6c674d233f949f070ff10c131f3713b78b4e (diff)
pandoc-cli: support "lua" and "serve" as commands
Pandoc behaves like `pandoc-lua` and `pandoc-server` if the first argument is `lua` and `serve`, respectively.
Diffstat (limited to 'pandoc-cli')
-rw-r--r--pandoc-cli/no-server/PandocCLI/Server.hs4
-rw-r--r--pandoc-cli/server/PandocCLI/Server.hs8
-rw-r--r--pandoc-cli/src/pandoc.hs10
3 files changed, 13 insertions, 9 deletions
diff --git a/pandoc-cli/no-server/PandocCLI/Server.hs b/pandoc-cli/no-server/PandocCLI/Server.hs
index 1f29be9f0..c2b391cbd 100644
--- a/pandoc-cli/no-server/PandocCLI/Server.hs
+++ b/pandoc-cli/no-server/PandocCLI/Server.hs
@@ -23,8 +23,8 @@ runCGI = serverUnsupported
-- | Placeholder function for the HTTP server; prints an error message
-- and exists with error code.
-runServer :: IO ()
-runServer = serverUnsupported
+runServer :: [String] -> IO ()
+runServer _args = serverUnsupported
serverUnsupported :: IO ()
serverUnsupported = do
diff --git a/pandoc-cli/server/PandocCLI/Server.hs b/pandoc-cli/server/PandocCLI/Server.hs
index ce9b4e8d0..3f04ab1b0 100644
--- a/pandoc-cli/server/PandocCLI/Server.hs
+++ b/pandoc-cli/server/PandocCLI/Server.hs
@@ -17,7 +17,7 @@ import qualified Network.Wai.Handler.Warp as Warp
import Network.Wai.Middleware.Timeout (timeout)
import Safe (readDef)
import System.Environment (lookupEnv)
-import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app)
+import Text.Pandoc.Server (ServerOpts(..), parseServerOptsFromArgs, app)
-- | Runs the CGI server.
runCGI :: IO ()
@@ -26,7 +26,7 @@ runCGI = do
CGI.run (timeout cgiTimeout app)
-- | Runs the HTTP server.
-runServer :: IO ()
-runServer = do
- sopts <- parseServerOpts
+runServer :: [String] -> IO ()
+runServer args = do
+ sopts <- parseServerOptsFromArgs args
Warp.run (serverPort sopts) (timeout (serverTimeout sopts) app)
diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs
index ca39b316f..630352c2c 100644
--- a/pandoc-cli/src/pandoc.hs
+++ b/pandoc-cli/src/pandoc.hs
@@ -31,10 +31,14 @@ main = E.handle (handleError . Left) $ do
rawArgs <- map UTF8.decodeArg <$> getArgs
case prg of
"pandoc-server.cgi" -> runCGI
- "pandoc-server" -> runServer
+ "pandoc-server" -> runServer rawArgs
"pandoc-lua" -> runLuaInterpreter prg rawArgs
- _ -> parseOptionsFromArgs options defaultOpts prg rawArgs
- >>= convertWithOpts
+ _ ->
+ case rawArgs of
+ "lua" : args -> runLuaInterpreter "pandoc lua" args
+ "serve" : args -> runServer args
+ _ -> parseOptionsFromArgs options defaultOpts prg rawArgs
+ >>= convertWithOpts
-- | Runs pandoc as a Lua interpreter that is (mostly) compatible with
-- the default @lua@ program shipping with Lua.