diff options
author | Joseph C. Sible <josephcsible@users.noreply.github.com> | 2020-02-07 02:42:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 08:42:46 +0100 |
commit | 60a3158bf9b6f4d16bb5fc6cac61b5c305ad40e3 (patch) | |
tree | 4112e9795a47630c48576393687f703e4de9e8e5 /src/Text/Pandoc/App | |
parent | a5a3ac994618d71ecaf2e8bd40251d792edc9c22 (diff) | |
download | pandoc-60a3158bf9b6f4d16bb5fc6cac61b5c305ad40e3.tar.gz |
More in-depth refactoring and cleanup (#6123)
* Avoid duplicating the dash case
* Pull common functions out of case branches
* Make sure list lengths are only calculated once
* Use unless
* Simplify parseURIReference' and avoid an unnecessary call to length
* Use <$> instead of reimplementing it
* Use swap instead of reimplementing it
* Remove eta-expansion that's been unnecessary since 90f5dd8
* Use tailDef instead of reimplementing it
* Use second instead of fmap, per @tarleb
Diffstat (limited to 'src/Text/Pandoc/App')
-rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index be6bc66f1..e407d8854 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -28,6 +28,7 @@ import Control.Monad.Trans import Control.Monad.Except (throwError) import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder, defConfig, Indent(..), NumberFormat(..)) +import Data.Bifunctor (second) import Data.Char (toLower) import Data.List (intercalate, sort) #ifdef _WINDOWS @@ -36,6 +37,7 @@ import Data.List (isPrefixOf) #endif #endif import Data.Maybe (fromMaybe, isJust) +import Safe (tailDef) import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme) import System.Console.GetOpt import System.Environment (getArgs, getProgName) @@ -981,10 +983,7 @@ writersNames = sort ("pdf" : map (T.unpack . fst) (writers :: [(Text, Writer PandocIO)])) splitField :: String -> (String, String) -splitField s = - case break (`elemText` ":=") s of - (k,_:v) -> (k,v) - (k,[]) -> (k,"true") +splitField = second (tailDef "true") . break (`elemText` ":=") -- | Apply defaults from --defaults file. applyDefaults :: Opt -> FilePath -> IO Opt @@ -994,10 +993,10 @@ applyDefaults opt file = runIOorExplode $ do else file setVerbosity $ optVerbosity opt dataDirs <- liftIO defaultUserDataDirs - let fps = case optDataDir opt of - Nothing -> (fp : map (</> ("defaults" </> fp)) - dataDirs) - Just dd -> [fp, dd </> "defaults" </> fp] + let fps = fp : case optDataDir opt of + Nothing -> map (</> ("defaults" </> fp)) + dataDirs + Just dd -> [dd </> "defaults" </> fp] fp' <- fromMaybe fp <$> findFile fps inp <- readFileLazy fp' case Y.decode1 inp of |