clarify recent print changes a bit (#551)

This commit is contained in:
Simon Michael 2017-05-30 13:39:53 -07:00
parent 4f712754e4
commit c9e7bbdc7c
2 changed files with 14 additions and 17 deletions

View File

@ -96,6 +96,7 @@ posting = nullposting
post :: AccountName -> Amount -> Posting post :: AccountName -> Amount -> Posting
post acct amt = posting {paccount=acct, pamount=Mixed [amt]} post acct amt = posting {paccount=acct, pamount=Mixed [amt]}
-- Get the original posting, if any.
originalPosting :: Posting -> Posting originalPosting :: Posting -> Posting
originalPosting p = fromMaybe p $ porigin p originalPosting p = fromMaybe p $ porigin p

View File

@ -9,7 +9,7 @@ A ledger-compatible @print@ command.
module Hledger.Cli.Print ( module Hledger.Cli.Print (
printmode printmode
,print' ,print'
,entriesReportAsText -- ,entriesReportAsText
,originalTransaction ,originalTransaction
,tests_Hledger_Cli_Print ,tests_Hledger_Cli_Print
) )
@ -46,17 +46,6 @@ printmode = (defCommandMode $ ["print"] ++ aliases) {
} }
where aliases = [] where aliases = []
showTransaction' :: CliOpts -> Transaction -> String
showTransaction' opts
| boolopt "explicit" $ rawopts_ opts = showTransactionUnelided
| otherwise = showTransactionUnelided . originalTransaction
originalTransaction :: Transaction -> Transaction
originalTransaction t = t { tpostings = map originalPosting' $ tpostings t } where
-- We don't want plain original postings because print wouldn't issue alias
-- directives. Thus we are going to print effective account name.
originalPosting' p = (originalPosting p) { paccount = paccount p }
-- | Print journal transactions in standard format. -- | Print journal transactions in standard format.
print' :: CliOpts -> Journal -> IO () print' :: CliOpts -> Journal -> IO ()
print' opts j = do print' opts j = do
@ -71,14 +60,21 @@ printEntries opts@CliOpts{reportopts_=ropts} j = do
fmt = outputFormatFromOpts opts fmt = outputFormatFromOpts opts
(render, ropts') = case fmt of (render, ropts') = case fmt of
"csv" -> ((++"\n") . printCSV . entriesReportAsCsv, ropts{accountlistmode_=ALFlat}) "csv" -> ((++"\n") . printCSV . entriesReportAsCsv, ropts{accountlistmode_=ALFlat})
_ -> (entriesReportAsText' opts, ropts) _ -> (entriesReportAsText opts, ropts)
writeOutput opts $ render $ entriesReport ropts' q j writeOutput opts $ render $ entriesReport ropts' q j
entriesReportAsText :: EntriesReport -> String entriesReportAsText :: CliOpts -> EntriesReport -> String
entriesReportAsText items = concatMap showTransactionUnelided items entriesReportAsText opts = concatMap (showTransactionUnelided . gettxn)
where
gettxn | boolopt "explicit" $ rawopts_ opts = id -- use the fully inferred/explicit txn
| otherwise = originalTransaction -- use the original txn (more or less)
entriesReportAsText' :: CliOpts -> EntriesReport -> String -- Replace this transaction's postings with the original postings if any, but keep the
entriesReportAsText' = concatMap . showTransaction' -- current possibly rewritten account names.
originalTransaction t = t { tpostings = map originalPostingPreservingAccount $ tpostings t }
-- Get the original posting if any, but keep the current possibly rewritten account name.
originalPostingPreservingAccount p = (originalPosting p) { paccount = paccount p }
-- XXX -- XXX
-- tests_showTransactions = [ -- tests_showTransactions = [