aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-04-12 09:50:36 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-04-12 09:52:10 -0700
commit499c91dd9698c15bac2667a90b2b3ddc1a0f1930 (patch)
treef43f6216429cc1c342681be4e77bd65b6945ebe8 /src/Text
parentc3d0cc9b8e9853f7435328a0f07bc6edccffd225 (diff)
downloadpandoc-499c91dd9698c15bac2667a90b2b3ddc1a0f1930.tar.gz
Fix bash completion for `--print-default-data-file`.
Previously this looked in the filesystem, even if pandoc was compiled with `embed_data_files` (and sometimes it looked in a nonexistent build directory). Now the bash completion script just includes a hard-coded list of data file names. See #4549.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/App.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 76d1d79c0..b3c51211a 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -66,7 +66,11 @@ import Data.Yaml (decode)
import qualified Data.Yaml as Yaml
import GHC.Generics
import Network.URI (URI (..), parseURI)
+#ifdef EMBED_DATA_FILES
+import Text.Pandoc.Data (dataFiles)
+#else
import Paths_pandoc (getDataDir)
+#endif
import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
defConfig, Indent(..), NumberFormat(..))
import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
@@ -1475,7 +1479,7 @@ options =
, Option "" ["bash-completion"]
(NoArg
(\_ -> do
- ddir <- getDataDir
+ datafiles <- getDataFileNames
tpl <- runIOorExplode $
UTF8.toString <$>
readDefaultDataFile "bash_completion.tpl"
@@ -1487,7 +1491,7 @@ options =
(unwords readersNames)
(unwords writersNames)
(unwords $ map fst highlightingStyles)
- ddir
+ (unwords datafiles)
exitSuccess ))
"" -- "Print bash completion script"
@@ -1561,6 +1565,16 @@ options =
]
+getDataFileNames :: IO [FilePath]
+getDataFileNames = do
+#ifdef EMBED_DATA_FILES
+ let allDataFiles = map fst dataFiles
+#else
+ allDataFiles <- filter (\x -> x /= "." && x /= "..") <$>
+ (getDataDir >>= getDirectoryContents)
+#endif
+ return $ "reference.docx" : "reference.odt" : "reference.pptx" : allDataFiles
+
-- Returns usage message
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
usageMessage programName = usageInfo (programName ++ " [OPTIONS] [FILES]")