From 37607beaea4255aa80c75e4387acfc08a3608e44 Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Tue, 17 Apr 2018 18:48:10 +0100 Subject: [PATCH] lib, app, web: use readJournalFileWithOpts instead of readJournalFile whenever possible --- dev.hs | 4 ++-- hledger-api/hledger-api.hs | 2 +- hledger-lib/Hledger/Read.hs | 3 ++- hledger-web/Application.hs | 4 ++-- hledger-web/Hledger/Web/Main.hs | 2 +- hledger/Hledger/Cli/Main.hs | 2 +- hledger/bench/bench.hs | 7 ++++--- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dev.hs b/dev.hs index 29de7f9b5..c14a99737 100755 --- a/dev.hs +++ b/dev.hs @@ -51,7 +51,7 @@ timeReadJournal msg s = timeit msg $ either error id <$> readJournal Nothing Not main = do -- putStrLn $ regexReplaceCI "^aa" "xx" "aa:bb:cc:dd:ee" - (_t0,_j) <- timeit ("read "++journal) $ either error id <$> readJournalFile Nothing Nothing True journal + (_t0,_j) <- timeit ("read "++journal) $ either error id <$> readJournalFileWithOpts def journal return () -- printf "Total: %0.2fs\n" (sum [t0,t1,t2,t3,t4]) @@ -156,7 +156,7 @@ main = do -- benchWithTimeit = do -- getCurrentDirectory >>= printf "Benchmarking hledger in %s with timeit\n" -- let opts = defcliopts{output_file_=Just outputfile} --- (t0,j) <- timeit ("read "++inputfile) $ either error id <$> readJournalFile Nothing Nothing True inputfile +-- (t0,j) <- timeit ("read "++inputfile) $ either error id <$> readJournalFileWithOpts def inputfile -- (t1,_) <- timeit ("print") $ print' opts j -- (t2,_) <- timeit ("register") $ register opts j -- (t3,_) <- timeit ("balance") $ balance opts j diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index ccd554415..20d7c532a 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -91,7 +91,7 @@ main = do let defd = "." d = getArgWithDefault args defd (longOption "static-dir") - readJournalFile Nothing def f >>= either error' (serveApi h p d f) + readJournalFileWithOpts def f >>= either error' (serveApi h p d f) serveApi :: String -> Int -> FilePath -> FilePath -> Journal -> IO () serveApi h p d f j = do diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index 883c691f5..9cba6a65a 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -15,6 +15,7 @@ module Hledger.Read ( defaultJournal, defaultJournalPath, readJournalFilesWithOpts, + readJournalFileWithOpts, readJournalFiles, readJournalFile, requireJournalFileExists, @@ -91,7 +92,7 @@ type PrefixedFilePath = FilePath -- | Read the default journal file specified by the environment, or raise an error. defaultJournal :: IO Journal -defaultJournal = defaultJournalPath >>= readJournalFile Nothing def >>= either error' return +defaultJournal = defaultJournalPath >>= readJournalFileWithOpts def >>= either error' return -- | Get the default journal file path specified by the environment. -- Like ledger, we look first for the LEDGER_FILE environment diff --git a/hledger-web/Application.hs b/hledger-web/Application.hs index 390476963..cd3e65bc3 100644 --- a/hledger-web/Application.hs +++ b/hledger-web/Application.hs @@ -39,7 +39,7 @@ import Handler.SidebarR import Hledger.Web.WebOptions (WebOpts(..), defwebopts) import Hledger.Data (Journal, nulljournal) -import Hledger.Read (readJournalFile) +import Hledger.Read (readJournalFileWithOpts) import Hledger.Utils (error') import Hledger.Cli.CliOptions (defcliopts, journalFilePathFromOpts) @@ -80,7 +80,7 @@ makeFoundation conf opts = do getApplicationDev :: IO (Int, Application) getApplicationDev = do f <- head `fmap` journalFilePathFromOpts defcliopts -- XXX head should be safe for now - j <- either error' id `fmap` readJournalFile Nothing def f + j <- either error' id `fmap` readJournalFileWithOpts def f defaultDevelApp loader (makeApplication defwebopts j) where loader = Yesod.Default.Config.loadConfig (configSettings Development) diff --git a/hledger-web/Hledger/Web/Main.hs b/hledger-web/Hledger/Web/Main.hs index 968e0b387..2bfa562f0 100644 --- a/hledger-web/Hledger/Web/Main.hs +++ b/hledger-web/Hledger/Web/Main.hs @@ -66,7 +66,7 @@ withJournalDo' opts@WebOpts {cliopts_ = cliopts} cmd = do . journalApplyAliases (aliasesFromOpts cliopts) <=< journalApplyValue (reportopts_ cliopts) <=< journalAddForecast cliopts - readJournalFile Nothing def f >>= either error' fn + readJournalFileWithOpts def f >>= either error' fn -- | The web command. web :: WebOpts -> Journal -> IO () diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index a0a1b16db..d80de29a3 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -19,7 +19,7 @@ You can use the command line: or ghci: > $ ghci hledger -> > j <- readJournalFile Nothing Nothing True "examples/sample.journal" +> > j <- readJournalFileWithOpts def "examples/sample.journal" > > register [] ["income","expenses"] j > 2008/01/01 income income:salary $-1 $-1 > 2008/06/01 gift income:gifts $-1 $-2 diff --git a/hledger/bench/bench.hs b/hledger/bench/bench.hs index 37c24f1ee..98f5d3b8f 100644 --- a/hledger/bench/bench.hs +++ b/hledger/bench/bench.hs @@ -4,6 +4,7 @@ import Criterion.Main (defaultMainWith, defaultConfig, bench, nfIO) -- import QuickBench (defaultMain) +import Data.Default import System.Directory (getCurrentDirectory) import System.Environment (getArgs, withArgs) import System.TimeIt (timeItT) @@ -33,7 +34,7 @@ main = do benchWithTimeit = do getCurrentDirectory >>= printf "Benchmarking hledger in %s with timeit\n" let opts = defcliopts{output_file_=Just outputfile} - (t0,j) <- timeit ("read "++inputfile) $ either error id <$> readJournalFile Nothing Nothing True inputfile + (t0,j) <- timeit ("read "++inputfile) $ either error id <$> readJournalFileWithOpts def inputfile (t1,_) <- timeit ("print") $ print' opts j (t2,_) <- timeit ("register") $ register opts j (t3,_) <- timeit ("balance") $ balance opts j @@ -49,9 +50,9 @@ timeit name action = do benchWithCriterion = do getCurrentDirectory >>= printf "Benchmarking hledger in %s with criterion\n" let opts = defcliopts{output_file_=Just "/dev/null"} - j <- either error id <$> readJournalFile Nothing Nothing True inputfile + j <- either error id <$> readJournalFileWithOpts def inputfile Criterion.Main.defaultMainWith defaultConfig $ [ - bench ("read "++inputfile) $ nfIO $ (either error const <$> readJournalFile Nothing Nothing True inputfile), + bench ("read "++inputfile) $ nfIO $ (either error const <$> readJournalFileWithOpts def inputfile), bench ("print") $ nfIO $ print' opts j, bench ("register") $ nfIO $ register opts j, bench ("balance") $ nfIO $ balance opts j,