hledger/Commands/Print.hs
2009-12-16 07:00:43 +00:00

30 lines
810 B
Haskell

{-|
A ledger-compatible @print@ command.
-}
module Commands.Print
where
import Prelude hiding (putStr)
import Ledger
import Options
import System.IO.UTF8
-- | Print ledger transactions in standard format.
print' :: [Opt] -> [String] -> Ledger -> IO ()
print' opts args = putStr . showLedgerTransactions opts args
showLedgerTransactions :: [Opt] -> [String] -> Ledger -> String
showLedgerTransactions opts args l = concatMap (showLedgerTransactionForPrint effective) txns
where
txns = sortBy (comparing ltdate) $
ledger_txns $
filterJournalPostingsByDepth depth $
filterJournalTransactionsByAccount apats $
journal l
depth = depthFromOpts opts
effective = Effective `elem` opts
(apats,_) = parsePatternArgs args