aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/App
diff options
context:
space:
mode:
authorJoseph C. Sible <josephcsible@users.noreply.github.com>2020-02-08 12:12:30 -0500
committerGitHub <noreply@github.com>2020-02-08 09:12:30 -0800
commitf2f559003e4fe40c3623d1b7acfbeea5a8da9f34 (patch)
tree0dff787cd84437eb8ddd5396187920a72804c48e /src/Text/Pandoc/App
parent12c75701be4b87fc438be68af5658d71e5578f62 (diff)
downloadpandoc-f2f559003e4fe40c3623d1b7acfbeea5a8da9f34.tar.gz
Factor out a findM function (#6125)
This adds a new function to the API: Text.Pandoc.Shared.findM.
Diffstat (limited to 'src/Text/Pandoc/App')
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs12
1 files changed, 2 insertions, 10 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index 18d15843e..2a4942841 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -50,7 +50,7 @@ import Text.Pandoc
import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), IpynbOutput (..), addMeta)
import Text.Pandoc.Filter (Filter (..))
import Text.Pandoc.Highlighting (highlightingStyles)
-import Text.Pandoc.Shared (ordNub, elemText, safeStrRead, defaultUserDataDirs)
+import Text.Pandoc.Shared (ordNub, elemText, safeStrRead, defaultUserDataDirs, findM)
import Text.Printf
#ifdef EMBED_DATA_FILES
@@ -118,14 +118,6 @@ engines = map ("html",) htmlEngines ++
pdfEngines :: [String]
pdfEngines = ordNub $ map snd engines
-findFile :: PandocMonad m => [FilePath] -> m (Maybe FilePath)
-findFile [] = return Nothing
-findFile (f:fs) = do
- exists <- fileExists f
- if exists
- then return $ Just f
- else findFile fs
-
-- | A list of functions, each transforming the options data structure
-- in response to a command-line option.
options :: [OptDescr (Opt -> IO Opt)]
@@ -996,7 +988,7 @@ applyDefaults opt file = runIOorExplode $ do
Nothing -> map (</> ("defaults" </> fp))
dataDirs
Just dd -> [dd </> "defaults" </> fp]
- fp' <- fromMaybe fp <$> findFile fps
+ fp' <- fromMaybe fp <$> findM fileExists fps
inp <- readFileLazy fp'
case Y.decode1 inp of
Right (f :: Opt -> Opt) -> return $ f opt