2008-10-10 14:04:26 +04:00
|
|
|
{-|
|
|
|
|
|
2008-10-12 13:17:21 +04:00
|
|
|
Utilities for top-level modules and/or ghci. See also "Ledger.Utils".
|
2008-10-10 14:04:26 +04:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Utils
|
|
|
|
where
|
|
|
|
import qualified Data.Map as Map (lookup)
|
|
|
|
import Options
|
|
|
|
import Ledger
|
|
|
|
|
|
|
|
|
|
|
|
-- | get a RawLedger from the given file path
|
|
|
|
rawledgerfromfile :: FilePath -> IO RawLedger
|
|
|
|
rawledgerfromfile f = do
|
|
|
|
parsed <- parseLedgerFile f
|
|
|
|
return $ either (\_ -> RawLedger [] [] [] "") id parsed
|
|
|
|
|
|
|
|
-- | get a cached Ledger from the given file path
|
|
|
|
ledgerfromfile :: FilePath -> IO Ledger
|
|
|
|
ledgerfromfile f = do
|
|
|
|
l <- rawledgerfromfile f
|
2008-10-12 11:46:54 +04:00
|
|
|
return $ cacheLedger $ filterRawLedger "" "" wildcard l
|
2008-10-10 14:04:26 +04:00
|
|
|
|
|
|
|
-- | get a RawLedger from the file your LEDGER environment variable
|
|
|
|
-- variable points to or (WARNING) an empty one if there was a problem.
|
|
|
|
myrawledger :: IO RawLedger
|
|
|
|
myrawledger = do
|
|
|
|
parsed <- ledgerFilePathFromOpts [] >>= parseLedgerFile
|
|
|
|
return $ either (\_ -> RawLedger [] [] [] "") id parsed
|
|
|
|
|
|
|
|
-- | get a cached Ledger from the file your LEDGER environment variable
|
|
|
|
-- variable points to or (WARNING) an empty one if there was a problem.
|
|
|
|
myledger :: IO Ledger
|
|
|
|
myledger = do
|
|
|
|
l <- myrawledger
|
2008-10-12 11:46:54 +04:00
|
|
|
return $ cacheLedger $ filterRawLedger "" "" wildcard l
|
2008-10-10 14:04:26 +04:00
|
|
|
|
|
|
|
-- | get a named account from your ledger file
|
|
|
|
myaccount :: AccountName -> IO Account
|
2008-10-11 02:28:10 +04:00
|
|
|
myaccount a = myledger >>= (return . fromMaybe nullacct . Map.lookup a . accountmap)
|
2008-10-10 14:04:26 +04:00
|
|
|
|