diff options
| author | Albert Krewinkel <[email protected]> | 2022-09-27 11:59:52 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-09-27 08:42:27 -0700 |
| commit | 175b791529a960bf7df8bccb8876783076b3d321 (patch) | |
| tree | 17df31777977ce93e22960b8796c56bde3967e7e | |
| parent | a3fd6c674d233f949f070ff10c131f3713b78b4e (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.
| -rw-r--r-- | MANUAL.txt | 20 | ||||
| -rw-r--r-- | pandoc-cli/no-server/PandocCLI/Server.hs | 4 | ||||
| -rw-r--r-- | pandoc-cli/server/PandocCLI/Server.hs | 8 | ||||
| -rw-r--r-- | pandoc-cli/src/pandoc.hs | 10 | ||||
| -rw-r--r-- | pandoc-server/src/Text/Pandoc/Server.hs | 6 |
5 files changed, 28 insertions, 20 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index 01b22b630..e99c84ef5 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -7081,10 +7081,10 @@ metadata field (see [EPUB Metadata], above). # Running pandoc as a web server If you rename (or symlink) the pandoc executable to -`pandoc-server`, it will start up a web server with a JSON -API. This server exposes most of the conversion functionality -of pandoc. For full documentation, see the [pandoc-server] -man page. +`pandoc-server`, or if you call pandoc with `serve` as the first +argument, it will start up a web server with a JSON API. This +server exposes most of the conversion functionality of pandoc. For +full documentation, see the [pandoc-server] man page. If you rename (or symlink) the pandoc executable to `pandoc-server.cgi`, it will function as a CGI program @@ -7098,12 +7098,12 @@ will be performed on the server during pandoc conversions. # Running pandoc as a Lua interpreter -Calling the pandoc executable under the name `pandoc-lua` will -make it function as a standalone Lua interpreter. The behavior is -mostly identical to that of the [standalone `lua` -executable][lua standalone], version 5.4. However, there is no -REPL yet, and the options `-W`, `-E`, and `-i` currently don't -have any effect. +Calling the pandoc executable under the name `pandoc-lua` or with +`lua` as the first argument will make it function as a standalone +Lua interpreter. The behavior is mostly identical to that of the +[standalone `lua` executable][lua standalone], version 5.4. +However, there is no REPL yet, and the options `-W`, `-E`, and +`-i` currently don't have any effect. [lua standalone]: https://www.lua.org/manual/5.4/manual.html#7 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. diff --git a/pandoc-server/src/Text/Pandoc/Server.hs b/pandoc-server/src/Text/Pandoc/Server.hs index 04dffb12a..9b6f4eedc 100644 --- a/pandoc-server/src/Text/Pandoc/Server.hs +++ b/pandoc-server/src/Text/Pandoc/Server.hs @@ -10,6 +10,7 @@ module Text.Pandoc.Server , Params(..) , Blob(..) , parseServerOpts + , parseServerOptsFromArgs ) where import Data.Aeson @@ -94,6 +95,10 @@ cliOptions = parseServerOpts :: IO ServerOpts parseServerOpts = do args <- getArgs + parseServerOptsFromArgs args + +parseServerOptsFromArgs :: [String] -> IO ServerOpts +parseServerOptsFromArgs args = do let handleUnknownOpt x = "Unknown option: " <> x case getOpt' Permute cliOptions args of (os, ns, unrecognizedOpts, es) -> do @@ -426,4 +431,3 @@ server = convertBytes case res of Left e -> throwError $ PandocTemplateError (T.pack e) Right tpl -> return tpl - |
