mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-26 10:16:32 +00:00
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.
This commit is contained in:
committed by
John MacFarlane
parent
a3fd6c674d
commit
175b791529
+10
-10
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user