From 059ad9eb760f412c2a2591da21e139ec0783476d Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 17 Sep 2018 05:52:13 -0700 Subject: [PATCH] refactor: jaccounts -> jdeclaredaccounts --- hledger-lib/Hledger/Data/Account.hs | 2 +- hledger-lib/Hledger/Data/Journal.hs | 6 +++--- hledger-lib/Hledger/Data/Types.hs | 2 +- hledger-lib/Hledger/Read/Common.hs | 2 +- hledger-lib/Hledger/Read/JournalReader.hs | 2 +- hledger-lib/Hledger/Reports/BudgetReport.hs | 2 +- hledger-lib/Hledger/Reports/MultiBalanceReports.hs | 2 +- hledger/Hledger/Cli/Commands/Accounts.hs | 4 +++- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hledger-lib/Hledger/Data/Account.hs b/hledger-lib/Hledger/Data/Account.hs index 917f3bc45..f92d3cbdf 100644 --- a/hledger-lib/Hledger/Data/Account.hs +++ b/hledger-lib/Hledger/Data/Account.hs @@ -92,7 +92,7 @@ tieAccountParents = tie Nothing -- | Look up an account's numeric code, if any, from the Journal and set it. accountSetCodeFrom :: Journal -> Account -> Account -accountSetCodeFrom j a = a{acode=fromMaybe Nothing $ lookup (aname a) (jaccounts j)} +accountSetCodeFrom j a = a{acode=fromMaybe Nothing $ lookup (aname a) (jdeclaredaccounts j)} -- | Get this account's parent accounts, from the nearest up to the root. parentAccounts :: Account -> [Account] diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 9feb76825..65977094f 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -163,7 +163,7 @@ instance Sem.Semigroup Journal where ,jparsealiases = jparsealiases j2 -- ,jparsetransactioncount = jparsetransactioncount j1 + jparsetransactioncount j2 ,jparsetimeclockentries = jparsetimeclockentries j1 <> jparsetimeclockentries j2 - ,jaccounts = jaccounts j1 <> jaccounts j2 + ,jdeclaredaccounts = jdeclaredaccounts j1 <> jdeclaredaccounts j2 ,jcommodities = jcommodities j1 <> jcommodities j2 ,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2 ,jmarketprices = jmarketprices j1 <> jmarketprices j2 @@ -190,7 +190,7 @@ nulljournal = Journal { ,jparsealiases = [] -- ,jparsetransactioncount = 0 ,jparsetimeclockentries = [] - ,jaccounts = [] + ,jdeclaredaccounts = [] ,jcommodities = M.fromList [] ,jinferredcommodities = M.fromList [] ,jmarketprices = [] @@ -256,7 +256,7 @@ journalAccountNamesImplied = expandAccountNames . journalAccountNamesUsed -- | Sorted unique account names declared by account directives in this journal. journalAccountNamesDeclared :: Journal -> [AccountName] -journalAccountNamesDeclared = nub . sort . map fst . jaccounts +journalAccountNamesDeclared = nub . sort . map fst . jdeclaredaccounts -- | Sorted unique account names declared by account directives or posted to -- by transactions in this journal. diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index 04a9539a0..8d438befe 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -360,7 +360,7 @@ data Journal = Journal { -- ,jparsetransactioncount :: Integer -- ^ the current count of transactions parsed so far (only journal format txns, currently) ,jparsetimeclockentries :: [TimeclockEntry] -- ^ timeclock sessions which have not been clocked out -- principal data - ,jaccounts :: [(AccountName, Maybe AccountCode)] -- ^ accounts that have been declared by account directives + ,jdeclaredaccounts :: [(AccountName, Maybe AccountCode)] -- ^ Accounts declared by account directives, in parse order. ,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives ,jinferredcommodities :: M.Map CommoditySymbol AmountStyle -- ^ commodities and formats inferred from journal amounts XXX misnamed ,jmarketprices :: [MarketPrice] diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 3dc07e4a1..bd985e74c 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -266,7 +266,7 @@ getAmountStyle commodity = do return effectiveStyle pushAccount :: AccountName -> JournalParser m () -pushAccount acct = modify' (\j -> j{jaccounts = (acct, Nothing) : jaccounts j}) +pushAccount acct = modify' (\j -> j{jdeclaredaccounts = (acct, Nothing) : jdeclaredaccounts j}) pushParentAccount :: AccountName -> JournalParser m () pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j}) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 9d981e729..11eff94d9 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -266,7 +266,7 @@ accountdirectivep = do newline skipMany indentedlinep - modify' (\j -> j{jaccounts = (acct, macode) : jaccounts j}) + modify' (\j -> j{jdeclaredaccounts = (acct, macode) : jdeclaredaccounts j}) indentedlinep :: JournalParser m String indentedlinep = lift (skipSome spacenonewline) >> (rstrip <$> lift restofline) diff --git a/hledger-lib/Hledger/Reports/BudgetReport.hs b/hledger-lib/Hledger/Reports/BudgetReport.hs index 81eeb2a6b..c35f7e2bb 100644 --- a/hledger-lib/Hledger/Reports/BudgetReport.hs +++ b/hledger-lib/Hledger/Reports/BudgetReport.hs @@ -224,7 +224,7 @@ combineBudgetAndActual -- acodeandname r = (acode', aname) -- where -- aname = first6 r --- macode = fromMaybe Nothing $ lookup aname $ jaccounts j +-- macode = fromMaybe Nothing $ lookup aname $ jdeclaredaccounts j -- acode' = fromMaybe maxBound macode -- -- -- Sort the report rows, representing a tree of accounts, by account code and then account name at each level. diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReports.hs b/hledger-lib/Hledger/Reports/MultiBalanceReports.hs index f0907fc32..75a20e492 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReports.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReports.hs @@ -217,7 +217,7 @@ multiBalanceReport opts q j = acodeandname r = (acode', aname) where aname = first6 r - macode = fromMaybe Nothing $ lookup aname $ jaccounts j + macode = fromMaybe Nothing $ lookup aname $ jdeclaredaccounts j acode' = fromMaybe maxBound macode -- Sort the report rows, representing a tree of accounts, by account code and then account name at each level. diff --git a/hledger/Hledger/Cli/Commands/Accounts.hs b/hledger/Hledger/Cli/Commands/Accounts.hs index 96ed4483d..8e5e0cf0f 100644 --- a/hledger/Hledger/Cli/Commands/Accounts.hs +++ b/hledger/Hledger/Cli/Commands/Accounts.hs @@ -11,6 +11,7 @@ The @accounts@ command lists account names: -} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE CPP #-} module Hledger.Cli.Commands.Accounts ( @@ -49,6 +50,7 @@ accountsmode = (defCommandMode $ ["accounts"] ++ aliases) { groupUnnamed = [ flagNone ["declared"] (\opts -> setboolopt "declared" opts) "show account names declared with account directives" ,flagNone ["used"] (\opts -> setboolopt "used" opts) "show account names referenced by transactions" + ,flagNone ["codes"] (\opts -> setboolopt "codes" opts) "also show numeric account codes" ,flagNone ["tree"] (\opts -> setboolopt "tree" opts) "show short account names, as a tree" ,flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show full account names, as a list (default)" ,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts" @@ -66,7 +68,7 @@ accounts CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do let q = queryFromOpts d ropts nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q depth = dbg1 "depth" $ queryDepth $ filterQuery queryIsDepth q - matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ map fst $ jaccounts j + matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ map fst $ jdeclaredaccounts j matchedps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps used = boolopt "used" rawopts