mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-07 21:15:19 +03:00
lib, app, web: use readJournalFileWithOpts instead of readJournalFile whenever possible
This commit is contained in:
parent
c7d86f3572
commit
37607beaea
4
dev.hs
4
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 ()
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user