imp: accounts: --unused

This commit is contained in:
Simon Michael 2022-10-08 08:16:07 -10:00
parent 25c9083d0d
commit b16a02b2e6
2 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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