fix: bin: Get scripts compiling with current hledger-lib.
This commit is contained in:
parent
db45b13249
commit
8fcdc22a45
@ -43,4 +43,4 @@ main = do
|
|||||||
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
|
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
(report,j) <- withJournalDo opts $ \j -> return (multiBalanceReport rspec j, j)
|
(report,j) <- withJournalDo opts $ \j -> return (multiBalanceReport rspec j, j)
|
||||||
return (rsOpts rspec,j,report)
|
return (_rsReportOpts rspec,j,report)
|
||||||
|
|||||||
@ -116,6 +116,7 @@ import qualified Hledger.Data as H
|
|||||||
import qualified Hledger.Query as H
|
import qualified Hledger.Query as H
|
||||||
import qualified Hledger.Read as H
|
import qualified Hledger.Read as H
|
||||||
import qualified Hledger.Utils.Parse as H
|
import qualified Hledger.Utils.Parse as H
|
||||||
|
import Lens.Micro (set)
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
import "base-compat" Prelude.Compat ((<>))
|
import "base-compat" Prelude.Compat ((<>))
|
||||||
import System.Exit (exitFailure)
|
import System.Exit (exitFailure)
|
||||||
@ -127,7 +128,7 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
opts <- execParser args
|
opts <- execParser args
|
||||||
journalFile <- maybe H.defaultJournalPath pure (file opts)
|
journalFile <- maybe H.defaultJournalPath pure (file opts)
|
||||||
ejournal <- H.readJournalFile H.definputopts{H.ignore_assertions_=ignoreAssertions opts} journalFile
|
ejournal <- H.readJournalFile (set H.ignore_assertions (ignoreAssertions opts) H.definputopts) journalFile
|
||||||
case ejournal of
|
case ejournal of
|
||||||
Right j -> do
|
Right j -> do
|
||||||
(journal, starting) <- fixupJournal opts j
|
(journal, starting) <- fixupJournal opts j
|
||||||
@ -219,14 +220,14 @@ checkAssertion accounts = checkAssertion'
|
|||||||
evaluate (Account account) =
|
evaluate (Account account) =
|
||||||
fromMaybe H.nullmixedamt $ lookup account accounts
|
fromMaybe H.nullmixedamt $ lookup account accounts
|
||||||
evaluate (AccountNested account) =
|
evaluate (AccountNested account) =
|
||||||
maSum [m | (a,m) <- accounts, account == a || (a <> pack ":") `isPrefixOf` account]
|
H.maSum [m | (a,m) <- accounts, account == a || (a <> pack ":") `isPrefixOf` account]
|
||||||
evaluate (Amount amount) = H.mixed [amount]
|
evaluate (Amount amount) = H.mixed [amount]
|
||||||
|
|
||||||
-- Add missing amounts (with 0 value), normalise, throw away style
|
-- Add missing amounts (with 0 value), normalise, throw away style
|
||||||
-- information, and sort by commodity name.
|
-- information, and sort by commodity name.
|
||||||
fixup m1 m2 =
|
fixup m1 m2 =
|
||||||
let m = H.mixed $ amounts m1 ++ [m_ { H.aquantity = 0 } | m_ <- amounts m2]
|
let m = H.mixed $ H.amounts m1 ++ [m_ { H.aquantity = 0 } | m_ <- H.amounts m2]
|
||||||
as = amounts m
|
as = H.amounts m
|
||||||
in H.mixed $ sortOn H.acommodity . map (\a -> a { H.astyle = H.amountstyle }) $ as
|
in H.mixed $ sortOn H.acommodity . map (\a -> a { H.astyle = H.amountstyle }) $ as
|
||||||
|
|
||||||
-- | Check if an account name is mentioned in an assertion.
|
-- | Check if an account name is mentioned in an assertion.
|
||||||
@ -280,7 +281,7 @@ closingBalances' postings =
|
|||||||
|
|
||||||
-- | Add balances in matching accounts.
|
-- | Add balances in matching accounts.
|
||||||
addAccounts :: [(H.AccountName, H.MixedAmount)] -> [(H.AccountName, H.MixedAmount)] -> [(H.AccountName, H.MixedAmount)]
|
addAccounts :: [(H.AccountName, H.MixedAmount)] -> [(H.AccountName, H.MixedAmount)] -> [(H.AccountName, H.MixedAmount)]
|
||||||
addAccounts as1 as2 = [ (a, a1 `maPlus` a2)
|
addAccounts as1 as2 = [ (a, a1 `H.maPlus` a2)
|
||||||
| a <- nub (map fst as1 ++ map fst as2)
|
| a <- nub (map fst as1 ++ map fst as2)
|
||||||
, let a1 = fromMaybe H.nullmixedamt $ lookup a as1
|
, let a1 = fromMaybe H.nullmixedamt $ lookup a as1
|
||||||
, let a2 = fromMaybe H.nullmixedamt $ lookup a as2
|
, let a2 = fromMaybe H.nullmixedamt $ lookup a as2
|
||||||
|
|||||||
@ -65,7 +65,7 @@ main = do
|
|||||||
(_,report1) <- mbReport report1args
|
(_,report1) <- mbReport report1args
|
||||||
(rspec2,report2) <- mbReport report2args
|
(rspec2,report2) <- mbReport report2args
|
||||||
let merged = appendReports report1 report2
|
let merged = appendReports report1 report2
|
||||||
TL.putStrLn $ multiBalanceReportAsText (rsOpts rspec2) merged
|
TL.putStrLn $ multiBalanceReportAsText (_rsReportOpts rspec2) merged
|
||||||
where
|
where
|
||||||
mbReport args = do
|
mbReport args = do
|
||||||
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
|
opts@CliOpts{reportspec_=rspec} <- getHledgerCliOpts' cmdmode args
|
||||||
|
|||||||
@ -57,21 +57,21 @@ _FLAGS
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
copts@CliOpts{reportspec_=rspec, rawopts_} <- getHledgerCliOpts cmdmode
|
copts@CliOpts{reportspec_=rspec, rawopts_} <- getHledgerCliOpts cmdmode
|
||||||
let ropts = rsOpts rspec
|
let ropts = _rsReportOpts rspec
|
||||||
copts' = copts{
|
copts' = copts{
|
||||||
-- One of our postings will probably have a missing amount; this ensures it's
|
-- One of our postings will probably have a missing amount; this ensures it's
|
||||||
-- explicit on all the others.
|
-- 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
|
-- Don't let our ACCT argument be interpreted as a query by print
|
||||||
,reportspec_ = rspec{rsOpts=ropts{querystring_=[]}}
|
,reportspec_ = rspec{_rsReportOpts=ropts{querystring_=[]}}
|
||||||
}
|
}
|
||||||
withJournalDo copts' $ \j -> do
|
withJournalDo copts' $ \j -> do
|
||||||
today <- getCurrentDay
|
today <- getCurrentDay
|
||||||
let
|
let
|
||||||
menddate = reportPeriodLastDay rspec
|
menddate = reportPeriodLastDay rspec
|
||||||
q = rsQuery rspec
|
q = _rsQuery rspec
|
||||||
acct = headDef (error' "Please provide an account name argument") $ querystring_ ropts
|
acct = headDef (error' "Please provide an account name argument") $ querystring_ ropts
|
||||||
pr = postingsReport rspec{rsQuery = And [Acct $ accountNameToAccountRegexCI acct, q]} j
|
pr = postingsReport rspec{_rsQuery = And [Acct $ accountNameToAccountRegexCI acct, q]} j
|
||||||
|
|
||||||
-- dates of postings to acct (in report)
|
-- dates of postings to acct (in report)
|
||||||
pdates = map (postingDate . fourth5) pr
|
pdates = map (postingDate . fourth5) pr
|
||||||
|
|||||||
@ -33,7 +33,7 @@ main = do
|
|||||||
\j -> do
|
\j -> do
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
let
|
let
|
||||||
q = rsQuery rspec
|
q = _rsQuery rspec
|
||||||
ts = filter (q `matchesTransaction`) $ jtxns $ journalApplyValuationFromOpts rspec j
|
ts = filter (q `matchesTransaction`) $ jtxns $ journalApplyValuationFromOpts rspec j
|
||||||
ts' = map transactionSwapDates ts
|
ts' = map transactionSwapDates ts
|
||||||
mapM_ (T.putStrLn . showTransaction) ts'
|
mapM_ (T.putStrLn . showTransaction) ts'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user