mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 01:36:45 +00:00
[API Change] App: parameterize options over the scripting engine
This commit is contained in:
committed by
John MacFarlane
parent
78814f27e0
commit
0ab014ed1e
@@ -20,7 +20,7 @@ import Text.Pandoc.App ( convertWithOpts, defaultOpts, options
|
||||
, parseOptionsFromArgs)
|
||||
import Text.Pandoc.Class (runIOorExplode)
|
||||
import Text.Pandoc.Error (handleError)
|
||||
import Text.Pandoc.Lua (runLua, runLuaNoEnv)
|
||||
import Text.Pandoc.Lua (getEngine, runLua, runLuaNoEnv)
|
||||
import Text.Pandoc.Shared (pandocVersionText)
|
||||
import qualified Text.Pandoc.UTF8 as UTF8
|
||||
import PandocCLI.Server
|
||||
@@ -37,8 +37,10 @@ main = E.handle (handleError . Left) $ do
|
||||
case rawArgs of
|
||||
"lua" : args -> runLuaInterpreter "pandoc lua" args
|
||||
"serve" : args -> runServer args
|
||||
_ -> parseOptionsFromArgs options defaultOpts prg rawArgs
|
||||
>>= convertWithOpts
|
||||
_ -> do
|
||||
engine <- getEngine
|
||||
let opts = options engine
|
||||
parseOptionsFromArgs opts defaultOpts prg rawArgs >>= convertWithOpts
|
||||
|
||||
-- | Runs pandoc as a Lua interpreter that is (mostly) compatible with
|
||||
-- the default @lua@ program shipping with Lua.
|
||||
|
||||
@@ -53,6 +53,7 @@ import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), IpynbOutput (..),
|
||||
fullDefaultsPath)
|
||||
import Text.Pandoc.Filter (Filter (..))
|
||||
import Text.Pandoc.Highlighting (highlightingStyles, lookupHighlightingStyle)
|
||||
import Text.Pandoc.Scripting (ScriptingEngine (engineName))
|
||||
import Text.Pandoc.Shared (ordNub, elemText, safeStrRead, defaultUserDataDir)
|
||||
import Text.Printf
|
||||
|
||||
@@ -145,8 +146,8 @@ pdfEngines = ordNub $ map snd engines
|
||||
|
||||
-- | A list of functions, each transforming the options data structure
|
||||
-- in response to a command-line option.
|
||||
options :: [OptDescr (Opt -> IO Opt)]
|
||||
options =
|
||||
options :: ScriptingEngine -> [OptDescr (Opt -> IO Opt)]
|
||||
options scriptingEngine =
|
||||
[ Option "fr" ["from","read"]
|
||||
(ReqArg
|
||||
(\arg opt -> return opt { optFrom =
|
||||
@@ -828,7 +829,8 @@ options =
|
||||
let optnames (Option shorts longs _ _) =
|
||||
map (\c -> ['-',c]) shorts ++
|
||||
map ("--" ++) longs
|
||||
let allopts = unwords (concatMap optnames options)
|
||||
let allopts = unwords (concatMap optnames
|
||||
(options scriptingEngine))
|
||||
UTF8.hPutStrLn stdout $ T.pack $ printf tpl allopts
|
||||
(T.unpack $ T.unwords readersNames)
|
||||
(T.unpack $ T.unwords writersNames)
|
||||
@@ -960,14 +962,11 @@ options =
|
||||
(\_ -> do
|
||||
prg <- getProgName
|
||||
defaultDatadir <- defaultUserDataDir
|
||||
luaVersion <- HsLua.run @HsLua.Exception $ do
|
||||
openlibs
|
||||
getglobal "_VERSION"
|
||||
peek top
|
||||
UTF8.hPutStrLn stdout
|
||||
$ T.pack
|
||||
$ prg ++ " " ++ T.unpack pandocVersionText ++ versionSuffix ++
|
||||
compileInfo ++ "\nScripting engine: " ++ luaVersion ++
|
||||
compileInfo ++ "\nScripting engine: " ++
|
||||
T.unpack (engineName scriptingEngine) ++
|
||||
"\nUser data directory: " ++ defaultDatadir ++
|
||||
('\n':copyrightMessage)
|
||||
exitSuccess ))
|
||||
@@ -977,7 +976,8 @@ options =
|
||||
(NoArg
|
||||
(\_ -> do
|
||||
prg <- getProgName
|
||||
UTF8.hPutStr stdout (T.pack $ usageMessage prg options)
|
||||
UTF8.hPutStr stdout (T.pack $ usageMessage prg
|
||||
(options scriptingEngine))
|
||||
exitSuccess ))
|
||||
"" -- "Show help"
|
||||
]
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@ import qualified Control.Exception as E
|
||||
import Text.Pandoc.App (convertWithOpts, defaultOpts, options,
|
||||
parseOptionsFromArgs)
|
||||
import Text.Pandoc.Error (handleError)
|
||||
import Text.Pandoc.Scripting (noEngine)
|
||||
import GHC.IO.Encoding
|
||||
import Test.Tasty
|
||||
import qualified Tests.Command
|
||||
@@ -112,8 +113,8 @@ main = do
|
||||
case args of
|
||||
"--emulate":args' -> -- emulate pandoc executable
|
||||
E.catch
|
||||
(parseOptionsFromArgs options defaultOpts "pandoc" args' >>=
|
||||
convertWithOpts)
|
||||
(parseOptionsFromArgs (options noEngine) defaultOpts "pandoc" args'
|
||||
>>= convertWithOpts)
|
||||
(handleError . Left)
|
||||
_ -> inDirectory "test" $ do
|
||||
fp <- getExecutablePath
|
||||
|
||||
Reference in New Issue
Block a user