From f2f559003e4fe40c3623d1b7acfbeea5a8da9f34 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" <josephcsible@users.noreply.github.com> Date: Sat, 8 Feb 2020 12:12:30 -0500 Subject: Factor out a findM function (#6125) This adds a new function to the API: Text.Pandoc.Shared.findM. --- src/Text/Pandoc/App/CommandLineOptions.hs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/Text/Pandoc/App') 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 -- cgit v1.2.3