From a64d1aa6d0bcaf643bbe2607238026b4d26a3637 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Wed, 30 Dec 2020 17:59:12 +1100 Subject: [PATCH] bin: Update bin scripts for current hledger-lib. (cherry picked from commit bc4aef17b7fa13ec0754b93325e1c5e5ee04f1e7) --- bin/hledger-balance-as-budget.hs | 12 ++++++------ bin/hledger-check-fancyassertions.hs | 2 +- bin/hledger-combine-balances.hs | 18 ++++++++---------- bin/hledger-smooth.hs | 18 +++++++++--------- bin/hledger-swap-dates.hs | 6 +++--- hledger-lib/Hledger/Reports/BudgetReport.hs | 1 + 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/bin/hledger-balance-as-budget.hs b/bin/hledger-balance-as-budget.hs index 5d42c87ea..e7350cb3a 100755 --- a/bin/hledger-balance-as-budget.hs +++ b/bin/hledger-balance-as-budget.hs @@ -31,13 +31,13 @@ main = do args <- getArgs let report1args = takeWhile (/= "--") args let report2args = drop 1 $ dropWhile (/= "--") args - (_,report1) <- mbReport report1args - (ropts2,report2) <- mbReport report2args - let pastAsBudget = combineBudgetAndActual report1{prDates=prDates report2} report2 + (_,_,report1) <- mbReport report1args + (ropts2,j,report2) <- mbReport report2args + let pastAsBudget = combineBudgetAndActual ropts2 j report1{prDates=prDates report2} report2 putStrLn $ budgetReportAsText ropts2 pastAsBudget where mbReport args = do - opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts' cmdmode args + opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args d <- getCurrentDay - report <- withJournalDo opts (return . multiBalanceReport d ropts) - return (ropts,report) + (report,j) <- withJournalDo opts $ \j -> return (multiBalanceReport rspec j, j) + return (rsOpts rspec,j,report) diff --git a/bin/hledger-check-fancyassertions.hs b/bin/hledger-check-fancyassertions.hs index bb1522124..7052ce7c4 100755 --- a/bin/hledger-check-fancyassertions.hs +++ b/bin/hledger-check-fancyassertions.hs @@ -335,7 +335,7 @@ data Opts = Opts , assertionsAlways :: [(String, Predicate)] -- ^ Account assertions that must hold after each txn. } - deriving (Eq, Ord, Show) + deriving (Show) -- | Command-line arguments. args :: ParserInfo Opts diff --git a/bin/hledger-combine-balances.hs b/bin/hledger-combine-balances.hs index 809ac2b73..5dd042125 100755 --- a/bin/hledger-combine-balances.hs +++ b/bin/hledger-combine-balances.hs @@ -14,23 +14,22 @@ appendReports :: MultiBalanceReport -> MultiBalanceReport -> MultiBalanceReport appendReports r1 r2 = PeriodicReport { prDates = prDates r1 ++ prDates r2 - , prRows = map snd $ M.toAscList mergedRows + , prRows = map snd $ M.toAscList mergedRows , prTotals = mergeRows (prTotals r1) (prTotals r2) } where rowsByAcct report = M.fromList $ map (\r -> (prrName r, r)) (prRows report) r1map = rowsByAcct r1 r2map = rowsByAcct r2 - + mergedRows = merge (mapMissing left) (mapMissing right) (zipWithMatched both) r1map r2map left _ row = row{prrAmounts = prrAmounts row ++ [nullmixedamt]} right _ row = row{prrAmounts = nullmixedamt:(prrAmounts row) } both _ = mergeRows -- name/depth in the second row would be the same by contruction - mergeRows (PeriodicReportRow name depth amt1 tot1 avg1) (PeriodicReportRow _ _ amt2 tot2 avg2) = + mergeRows (PeriodicReportRow name amt1 tot1 avg1) (PeriodicReportRow _ amt2 tot2 avg2) = PeriodicReportRow { prrName = name - , prrDepth = depth , prrAmounts = amt1++amt2 , prrTotal = tot1+tot2 , prrAverage = averageMixedAmounts [avg1,avg2] @@ -61,12 +60,11 @@ main = do let report1args = takeWhile (/= "--") args let report2args = drop 1 $ dropWhile (/= "--") args (_,report1) <- mbReport report1args - (ropts2,report2) <- mbReport report2args + (rspec2,report2) <- mbReport report2args let merged = appendReports report1 report2 - putStrLn $ multiBalanceReportAsText ropts2 merged + putStrLn $ multiBalanceReportAsText (rsOpts rspec2) merged where mbReport args = do - opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts' cmdmode args - d <- getCurrentDay - report <- withJournalDo opts (return . multiBalanceReport d ropts) - return (ropts,report) + opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args + report <- withJournalDo opts (return . multiBalanceReport rspec) + return (rspec,report) diff --git a/bin/hledger-smooth.hs b/bin/hledger-smooth.hs index 30688cdb7..2ba770a9b 100755 --- a/bin/hledger-smooth.hs +++ b/bin/hledger-smooth.hs @@ -51,22 +51,22 @@ _FLAGS main :: IO () main = do - copts@CliOpts{reportopts_=ropts, rawopts_} <- getHledgerCliOpts cmdmode - let copts' = copts{ + copts@CliOpts{reportspec_=rspec, rawopts_} <- getHledgerCliOpts cmdmode + let ropts = rsOpts rspec + copts' = copts{ -- One of our postings will probably have a missing amount; this ensures it's -- explicit on all the others. - rawopts_=setboolopt "explicit" rawopts_ + rawopts_ = setboolopt "explicit" rawopts_ -- Don't let our ACCT argument be interpreted as a query by print - ,reportopts_=ropts{query_=""} + ,reportspec_ = rspec{rsOpts=ropts{querystring_=[]}} } withJournalDo copts' $ \j -> do today <- getCurrentDay let - menddate = reportPeriodLastDay ropts - args = words' $ query_ ropts - q = queryFromOpts today ropts - acct = T.pack $ headDef (error' "Please provide an account name argument") args - pr = postingsReport ropts (And [Acct $ accountNameToAccountRegexCI acct, q]) j + menddate = reportPeriodLastDay rspec + q = rsQuery rspec + acct = headDef (error' "Please provide an account name argument") $ querystring_ ropts + pr = postingsReport rspec{rsQuery = And [Acct $ accountNameToAccountRegexCI acct, q]} j -- dates of postings to acct (in report) pdates = map (postingDate . fourth5) (snd pr) diff --git a/bin/hledger-swap-dates.hs b/bin/hledger-swap-dates.hs index 9ad760081..f3eaa85bc 100755 --- a/bin/hledger-swap-dates.hs +++ b/bin/hledger-swap-dates.hs @@ -25,13 +25,13 @@ _FLAGS main :: IO () main = do - opts@CliOpts{reportopts_=ropts} <- getHledgerCliOpts cmdmode + opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts cmdmode withJournalDo opts $ \j -> do d <- getCurrentDay let - q = queryFromOpts d ropts - ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j + q = rsQuery rspec + ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts (rsOpts rspec) j ts' = map transactionSwapDates ts mapM_ (putStrLn . showTransaction) ts' diff --git a/hledger-lib/Hledger/Reports/BudgetReport.hs b/hledger-lib/Hledger/Reports/BudgetReport.hs index e738d7064..fffbf6635 100644 --- a/hledger-lib/Hledger/Reports/BudgetReport.hs +++ b/hledger-lib/Hledger/Reports/BudgetReport.hs @@ -21,6 +21,7 @@ module Hledger.Reports.BudgetReport ( budgetReportAsCsv, -- * Helpers reportPeriodName, + combineBudgetAndActual, -- * Tests tests_BudgetReport )