From 0ab014ed1e5890e338792fab98aecc45cd889f99 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 29 Sep 2022 14:09:48 +0200 Subject: [API Change] App: parameterize `options` over the scripting engine --- pandoc-cli/src/pandoc.hs | 8 +++++--- src/Text/Pandoc/App/CommandLineOptions.hs | 18 +++++++++--------- test/test-pandoc.hs | 5 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs index ca5cf6651..216198291 100644 --- a/pandoc-cli/src/pandoc.hs +++ b/pandoc-cli/src/pandoc.hs @@ -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. diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 8d5677b82..abd7703a4 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -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" ] diff --git a/test/test-pandoc.hs b/test/test-pandoc.hs index 5552bc450..467e264f0 100644 --- a/test/test-pandoc.hs +++ b/test/test-pandoc.hs @@ -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 -- cgit v1.2.3