From b16a02b2e657d5bece4534d0a1a7bb92e27567d9 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 8 Oct 2022 08:16:07 -1000 Subject: [PATCH] imp: accounts: --unused --- hledger/Hledger/Cli/Commands/Accounts.hs | 11 +++++++---- hledger/Hledger/Cli/Commands/Accounts.md | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Accounts.hs b/hledger/Hledger/Cli/Commands/Accounts.hs index ad0598aa1..60a510800 100644 --- a/hledger/Hledger/Cli/Commands/Accounts.hs +++ b/hledger/Hledger/Cli/Commands/Accounts.hs @@ -39,6 +39,7 @@ accountsmode = hledgerCommandMode [flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts" ,flagNone ["used"] (setboolopt "used") "show only accounts used by transactions" ,flagNone ["declared"] (setboolopt "declared") "show only accounts declared by account directive" + ,flagNone ["unused"] (setboolopt "unused") "show accounts declared but not used" ,flagNone ["undeclared"] (setboolopt "undeclared") "show accounts used but not declared" ,flagNone ["find"] (setboolopt "find") "find the first account matched by the first command argument (a case-insensitive infix regexp or account name)" ,flagNone ["types"] (setboolopt "types") "also show account types when known" @@ -57,6 +58,7 @@ accounts CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=query,_rsRepo let tree = tree_ ropts used = boolopt "used" rawopts decl = boolopt "declared" rawopts + unused = boolopt "unused" rawopts undecl = boolopt "undeclared" rawopts find_ = boolopt "find" rawopts types = boolopt "types" rawopts @@ -67,12 +69,12 @@ accounts CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=query,_rsRepo -- just the acct: part of the query will be reapplied later, after clipping acctq = dbg4 "acctq" $ filterQuery queryIsAcct query dep = dbg4 "depth" $ queryDepth $ filterQuery queryIsDepth query - matcheddeclaredaccts = - dbg4 "matcheddeclaredaccts" $ + matcheddeclaredaccts = dbg5 "matcheddeclaredaccts" $ nub $ - filter (matchesAccountExtra (journalAccountType j) (journalInheritedAccountTags j) nodepthq) - $ map fst $ jdeclaredaccounts j + filter (matchesAccountExtra (journalAccountType j) (journalInheritedAccountTags j) nodepthq) $ + map fst $ jdeclaredaccounts j matchedusedaccts = dbg5 "matchedusedaccts" $ nub $ map paccount $ journalPostings $ filterJournalPostings nodepthq j + matchedunusedaccts = dbg5 "matchedunusedaccts" $ nub $ matcheddeclaredaccts \\ matchedusedaccts matchedundeclaredaccts = dbg5 "matchedundeclaredaccts" $ nub $ matchedusedaccts \\ matcheddeclaredaccts -- keep synced with aregister matchedacct = dbg5 "matchedacct" $ @@ -89,6 +91,7 @@ accounts CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=query,_rsRepo accts = dbg5 "accts to show" $ if | find_ -> [matchedacct] | undecl -> matchedundeclaredaccts + | unused -> matchedunusedaccts | decl && not used -> matcheddeclaredaccts | not decl && used -> matchedusedaccts | otherwise -> matcheddeclaredaccts ++ matchedusedaccts diff --git a/hledger/Hledger/Cli/Commands/Accounts.md b/hledger/Hledger/Cli/Commands/Accounts.md index 9a9712357..b3d906e41 100644 --- a/hledger/Hledger/Cli/Commands/Accounts.md +++ b/hledger/Hledger/Cli/Commands/Accounts.md @@ -11,6 +11,7 @@ With query arguments, only matched account names and account names referenced by Or it can show just the used accounts (`--used`), the declared accounts (`--declared`), +the accounts declared but not used (`--unused`), the accounts used but not declared (`--undeclared`), or the first account matched by an account name pattern, if any (`--find`). @@ -28,8 +29,8 @@ these may be useful when troubleshooting account display order. With `--directives`, it adds the `account` keyword, showing valid account directives which can be pasted into a journal file. -This is useful together with `--undeclared` to update your account declarations -when `check accounts` reports undeclared accounts. +This is useful together with `--undeclared` when updating your account declarations +to satisfy `hledger check accounts`. The `--find` flag can be used to look up a single account name, in the same way that the `aregister` command does. It returns the alphanumerically-first matched