aboutsummaryrefslogtreecommitdiff
path: root/pandoc-cli
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-07-13 22:47:11 -0700
committerJohn MacFarlane <[email protected]>2025-07-13 22:47:11 -0700
commitee4c9352ee9282f348d9459eafc08cbc0c671a91 (patch)
treed2cb7fdf2ef2569a9f745a023a7fa02c0e61c3aa /pandoc-cli
parentcff9ace0db3ec62f9c0fc72529e531e1985133b9 (diff)
Remove code duplication around version info.
Text.Pandoc.App.CommandLineOptions and pandoc-cli/src/pandoc.hs had similar code for generating version information. To avoid duplication, we now export `versionInfo` from Text.Pandoc.App [API change]. (The function is reexported from the non-public module Text.Pandoc.App.CommandLineOptions.) This function has three parameters that can be filled in when it is called by pandoc-cli. This change will make it simpler to revise version information.
Diffstat (limited to 'pandoc-cli')
-rw-r--r--pandoc-cli/src/pandoc.hs39
1 files changed, 11 insertions, 28 deletions
diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs
index 9e82d02bc..d110c6f62 100644
--- a/pandoc-cli/src/pandoc.hs
+++ b/pandoc-cli/src/pandoc.hs
@@ -16,17 +16,12 @@ module Main where
import qualified Control.Exception as E
import System.Environment (getArgs, getProgName)
import Text.Pandoc.App ( convertWithOpts, defaultOpts, options
- , parseOptionsFromArgs, handleOptInfo )
+ , parseOptionsFromArgs, handleOptInfo, versionInfo )
import Text.Pandoc.Error (handleError)
-import System.Exit (exitSuccess)
import Data.Monoid (Any(..))
import PandocCLI.Lua
import PandocCLI.Server
-import qualified Text.Pandoc.UTF8 as UTF8
-import Text.Pandoc.Version (pandocVersion)
-import Text.Pandoc.Data (defaultUserDataDir)
import Text.Pandoc.Scripting (ScriptingEngine(..))
-import Data.Version (showVersion)
import qualified Data.Text as T
#ifdef NIGHTLY
@@ -51,7 +46,7 @@ main = E.handle (handleError . Left) $ do
let hasVersion = getAny $ foldMap
(\s -> Any (s == "-v" || s == "--version"))
(takeWhile (/= "--") rawArgs)
- let versionOr action = if hasVersion then versionInfo else action
+ let versionOr action = if hasVersion then versionInfoCLI else action
case prg of
"pandoc-server.cgi" -> versionOr runCGI
"pandoc-server" -> versionOr $ runServer rawArgs
@@ -67,37 +62,25 @@ main = E.handle (handleError . Left) $ do
Left e -> handleOptInfo engine e
Right opts -> convertWithOpts engine opts
-copyrightMessage :: String
-copyrightMessage =
- "Copyright (C) 2006-2024 John MacFarlane. Web: https://pandoc.org\n"
- ++
- "This is free software; see the source for copying conditions. There is no\n"
- ++
- "warranty, not even for merchantability or fitness for a particular purpose."
-flagSettings :: String
-flagSettings = "Features: " ++
+getFeatures :: [String]
+getFeatures = [
#ifdef VERSION_pandoc_server
"+server"
#else
"-server"
#endif
- ++ " " ++
+ ,
#ifdef VERSION_hslua_cli
"+lua"
#else
"-lua"
#endif
+ ]
-versionInfo :: IO ()
-versionInfo = do
- defaultDatadir <- defaultUserDataDir
+versionInfoCLI :: IO ()
+versionInfoCLI = do
scriptingEngine <- getEngine
- UTF8.putStr $ T.unlines $ map T.pack
- [ "pandoc " ++ showVersion pandocVersion ++ versionSuffix
- , flagSettings
- , "Scripting engine: " ++ T.unpack (engineName scriptingEngine)
- , "User data directory: " ++ defaultDatadir
- , copyrightMessage
- ]
- exitSuccess
+ versionInfo getFeatures
+ (Just $ T.unpack (engineName scriptingEngine))
+ versionSuffix