fix an unsafe ! in ledgerAccount; clarify that withLedgerDo does not cache the ledger
This commit is contained in:
parent
d449a64814
commit
357b27fb63
@ -54,10 +54,10 @@ aliases for easier interaction. Here's an example:
|
|||||||
module Ledger.Ledger
|
module Ledger.Ledger
|
||||||
where
|
where
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import Data.Map ((!), fromList)
|
import Data.Map (findWithDefault, fromList)
|
||||||
import Ledger.Utils
|
import Ledger.Utils
|
||||||
import Ledger.Types
|
import Ledger.Types
|
||||||
import Ledger.Account ()
|
import Ledger.Account (nullacct)
|
||||||
import Ledger.AccountName
|
import Ledger.AccountName
|
||||||
import Ledger.Journal
|
import Ledger.Journal
|
||||||
import Ledger.Posting
|
import Ledger.Posting
|
||||||
@ -100,9 +100,11 @@ type CachedLedger = Ledger
|
|||||||
ledgerAccountNames :: Ledger -> [AccountName]
|
ledgerAccountNames :: Ledger -> [AccountName]
|
||||||
ledgerAccountNames = drop 1 . flatten . accountnametree
|
ledgerAccountNames = drop 1 . flatten . accountnametree
|
||||||
|
|
||||||
-- | Get the named account from a ledger.
|
-- | Get the named account from a (cached) ledger.
|
||||||
|
-- If the ledger has not been cached (with crunchJournal or
|
||||||
|
-- cacheLedger'), this returns the null account.
|
||||||
ledgerAccount :: Ledger -> AccountName -> Account
|
ledgerAccount :: Ledger -> AccountName -> Account
|
||||||
ledgerAccount = (!) . accountmap
|
ledgerAccount l a = findWithDefault nullacct a $ accountmap l
|
||||||
|
|
||||||
-- | List a ledger's accounts, in tree order
|
-- | List a ledger's accounts, in tree order
|
||||||
ledgerAccounts :: Ledger -> [Account]
|
ledgerAccounts :: Ledger -> [Account]
|
||||||
|
|||||||
2
Utils.hs
2
Utils.hs
@ -21,6 +21,8 @@ import System.Time (ClockTime,getClockTime)
|
|||||||
|
|
||||||
-- | Parse the user's specified ledger file and run a hledger command on
|
-- | Parse the user's specified ledger file and run a hledger command on
|
||||||
-- it, or report a parse error. This function makes the whole thing go.
|
-- it, or report a parse error. This function makes the whole thing go.
|
||||||
|
-- Warning, this provides only an uncached Ledger (no accountnametree or
|
||||||
|
-- accountmap), so cmd must cacheLedger'/crunchJournal if needed.
|
||||||
withLedgerDo :: [Opt] -> [String] -> String -> ([Opt] -> [String] -> Ledger -> IO ()) -> IO ()
|
withLedgerDo :: [Opt] -> [String] -> String -> ([Opt] -> [String] -> Ledger -> IO ()) -> IO ()
|
||||||
withLedgerDo opts args cmdname cmd = do
|
withLedgerDo opts args cmdname cmd = do
|
||||||
-- We kludgily read the file before parsing to grab the full text, unless
|
-- We kludgily read the file before parsing to grab the full text, unless
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user