diff --git a/hledger/Hledger/Cli/Commands/Accounts.hs b/hledger/Hledger/Cli/Commands/Accounts.hs index 4b4cf8535..4697bb569 100644 --- a/hledger/Hledger/Cli/Commands/Accounts.hs +++ b/hledger/Hledger/Cli/Commands/Accounts.hs @@ -35,11 +35,20 @@ import Hledger.Cli.CliOptions accountsmode = (defCommandMode $ ["accounts"] ++ aliases) { modeHelp = "show account names" `withAliases` aliases ,modeHelpSuffix = [ - "This command lists the accounts referenced by matched postings (and in tree mode, their parents as well). The accounts can be depth-clipped (--depth N) or have their leading parts trimmed (--drop N)." + "This command lists account names, either declared with account directives" + ,"(--declared), posted to (--posted), or both (default)." + ,"With query arguments, only matched account names and account names" + ,"referenced by matched postings are shown." + ,"It shows a flat list by default. With `--tree`, it uses indentation to" + ,"show the account hierarchy." + ,"In flat mode you can add `--drop N` to omit the first few account name components." + ,"Account names can be depth-clipped with `--depth N` or depth:N." ] ,modeGroupFlags = C.Group { groupUnnamed = [ - flagNone ["tree"] (\opts -> setboolopt "tree" opts) "show short account names, as a tree" + flagNone ["declared"] (\opts -> setboolopt "declared" opts) "show account names declared with account directives" + ,flagNone ["posted"] (\opts -> setboolopt "posted" opts) "show account names posted to by transactions" + ,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" ] @@ -51,13 +60,19 @@ accountsmode = (defCommandMode $ ["accounts"] ++ aliases) { -- | The accounts command. accounts :: CliOpts -> Journal -> IO () -accounts CliOpts{reportopts_=ropts} j = do +accounts CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do d <- getCurrentDay let q = queryFromOpts d ropts nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q depth = dbg1 "depth" $ queryDepth $ filterQuery queryIsDepth q - ps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j - as = dbg1 "as" $ nub $ filter (not . T.null) $ map (clipAccountName depth) $ sort $ map paccount ps + matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ jaccounts j + matchedps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j + matchedpostedaccts = dbg1 "matchedpostedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps + posted = boolopt "posted" rawopts + declared = boolopt "declared" rawopts + as | declared && not posted = matcheddeclaredaccts + | not declared && posted = matchedpostedaccts + | otherwise = nub $ sort $ matcheddeclaredaccts ++ matchedpostedaccts as' | tree_ ropts = expandAccountNames as | otherwise = as render a | tree_ ropts = T.replicate (2 * (accountNameLevel a - 1)) " " <> accountLeafName a diff --git a/hledger/hledger.1 b/hledger/hledger.1 index 3cdbe1647..e8fd0c191 100644 --- a/hledger/hledger.1 +++ b/hledger/hledger.1 @@ -1200,8 +1200,18 @@ See also \f[C]hledger\f[] for a more organised command list, and Show account names. Alias: a. .TP +.B \f[C]\-\-declared\f[] +show account names declared with account directives +.RS +.RE +.TP +.B \f[C]\-\-posted\f[] +show account names posted to by transactions +.RS +.RE +.TP .B \f[C]\-\-tree\f[] -show short account names, as a tree +show short account names and their parents, as a tree .RS .RE .TP @@ -1215,16 +1225,17 @@ in flat mode: omit N leading account name parts .RS .RE .PP -This command lists all account names that are in use (ie, all the -accounts which have at least one transaction posting to them). -With query arguments, only matched account names are shown. -.PP +This command lists account names, either declared with account +directives (\[en]declared), posted to (\[en]posted), or both (default). +With query arguments, only matched account names and account names +referenced by matched postings are shown. It shows a flat list by default. With \f[C]\-\-tree\f[], it uses indentation to show the account hierarchy. -.PP In flat mode you can add \f[C]\-\-drop\ N\f[] to omit the first few account name components. +Account names can be depth\-clipped with \f[C]\-\-depth\ N\f[] or +depth:N. .PP Examples: .IP diff --git a/hledger/hledger.info b/hledger/hledger.info index 3fe49a91a..08988ca30 100644 --- a/hledger/hledger.info +++ b/hledger/hledger.info @@ -887,9 +887,15 @@ File: hledger.info, Node: accounts, Next: activity, Up: COMMANDS Show account names. Alias: a. +'--declared' + + show account names declared with account directives +'--posted' + + show account names posted to by transactions '--tree' - show short account names, as a tree + show short account names and their parents, as a tree '--flat' show full account names, as a list (default) @@ -897,15 +903,14 @@ Show account names. Alias: a. in flat mode: omit N leading account name parts - This command lists all account names that are in use (ie, all the -accounts which have at least one transaction posting to them). With -query arguments, only matched account names are shown. - - It shows a flat list by default. With '--tree', it uses indentation -to show the account hierarchy. - - In flat mode you can add '--drop N' to omit the first few account -name components. + This command lists account names, either declared with account +directives (-declared), posted to (-posted), or both (default). With +query arguments, only matched account names and account names referenced +by matched postings are shown. It shows a flat list by default. With +'--tree', it uses indentation to show the account hierarchy. In flat +mode you can add '--drop N' to omit the first few account name +components. Account names can be depth-clipped with '--depth N' or +depth:N. Examples: @@ -2418,95 +2423,95 @@ Node: COMMANDS28399 Ref: #commands28511 Node: accounts29493 Ref: #accounts29591 -Node: activity30584 -Ref: #activity30694 -Node: add31054 -Ref: #add31153 -Node: balance33814 -Ref: #balance33925 -Node: Flat mode37299 -Ref: #flat-mode37424 -Node: Depth limited balance reports37844 -Ref: #depth-limited-balance-reports38045 -Node: Multicolumn balance reports38465 -Ref: #multicolumn-balance-reports38660 -Node: Budgets43349 -Ref: #budgets43496 -Node: Custom balance output47327 -Ref: #custom-balance-output47489 -Node: Colour support49582 -Ref: #colour-support49741 -Node: Output destination49914 -Ref: #output-destination50070 -Node: CSV output50340 -Ref: #csv-output50457 -Node: balancesheet50854 -Ref: #balancesheet50990 -Node: balancesheetequity53217 -Ref: #balancesheetequity53366 -Node: cashflow53903 -Ref: #cashflow54031 -Node: check-dates56070 -Ref: #check-dates56197 -Node: check-dupes56314 -Ref: #check-dupes56438 -Node: close56575 -Ref: #close56682 -Node: help57012 -Ref: #help57112 -Node: import58186 -Ref: #import58300 -Node: incomestatement59030 -Ref: #incomestatement59164 -Node: prices61484 -Ref: #prices61599 -Node: print61642 -Ref: #print61752 -Node: print-unique66637 -Ref: #print-unique66763 -Node: register66831 -Ref: #register66958 -Node: Custom register output71459 -Ref: #custom-register-output71588 -Node: register-match72885 -Ref: #register-match73019 -Node: rewrite73202 -Ref: #rewrite73319 -Node: stats73388 -Ref: #stats73491 -Node: tags74373 -Ref: #tags74471 -Node: test74707 -Ref: #test74791 -Node: ADD-ON COMMANDS75159 -Ref: #add-on-commands75269 -Node: Official add-ons76556 -Ref: #official-add-ons76696 -Node: api76783 -Ref: #api76872 -Node: ui76924 -Ref: #ui77023 -Node: web77081 -Ref: #web77170 -Node: Third party add-ons77216 -Ref: #third-party-add-ons77391 -Node: diff77526 -Ref: #diff77623 -Node: iadd77722 -Ref: #iadd77836 -Node: interest77919 -Ref: #interest78040 -Node: irr78135 -Ref: #irr78233 -Node: Experimental add-ons78311 -Ref: #experimental-add-ons78463 -Node: autosync78754 -Ref: #autosync78866 -Node: budget79105 -Ref: #budget79227 -Node: chart79293 -Ref: #chart79410 -Node: check79481 -Ref: #check79583 +Node: activity30841 +Ref: #activity30951 +Node: add31311 +Ref: #add31410 +Node: balance34071 +Ref: #balance34182 +Node: Flat mode37556 +Ref: #flat-mode37681 +Node: Depth limited balance reports38101 +Ref: #depth-limited-balance-reports38302 +Node: Multicolumn balance reports38722 +Ref: #multicolumn-balance-reports38917 +Node: Budgets43606 +Ref: #budgets43753 +Node: Custom balance output47584 +Ref: #custom-balance-output47746 +Node: Colour support49839 +Ref: #colour-support49998 +Node: Output destination50171 +Ref: #output-destination50327 +Node: CSV output50597 +Ref: #csv-output50714 +Node: balancesheet51111 +Ref: #balancesheet51247 +Node: balancesheetequity53474 +Ref: #balancesheetequity53623 +Node: cashflow54160 +Ref: #cashflow54288 +Node: check-dates56327 +Ref: #check-dates56454 +Node: check-dupes56571 +Ref: #check-dupes56695 +Node: close56832 +Ref: #close56939 +Node: help57269 +Ref: #help57369 +Node: import58443 +Ref: #import58557 +Node: incomestatement59287 +Ref: #incomestatement59421 +Node: prices61741 +Ref: #prices61856 +Node: print61899 +Ref: #print62009 +Node: print-unique66894 +Ref: #print-unique67020 +Node: register67088 +Ref: #register67215 +Node: Custom register output71716 +Ref: #custom-register-output71845 +Node: register-match73142 +Ref: #register-match73276 +Node: rewrite73459 +Ref: #rewrite73576 +Node: stats73645 +Ref: #stats73748 +Node: tags74630 +Ref: #tags74728 +Node: test74964 +Ref: #test75048 +Node: ADD-ON COMMANDS75416 +Ref: #add-on-commands75526 +Node: Official add-ons76813 +Ref: #official-add-ons76953 +Node: api77040 +Ref: #api77129 +Node: ui77181 +Ref: #ui77280 +Node: web77338 +Ref: #web77427 +Node: Third party add-ons77473 +Ref: #third-party-add-ons77648 +Node: diff77783 +Ref: #diff77880 +Node: iadd77979 +Ref: #iadd78093 +Node: interest78176 +Ref: #interest78297 +Node: irr78392 +Ref: #irr78490 +Node: Experimental add-ons78568 +Ref: #experimental-add-ons78720 +Node: autosync79011 +Ref: #autosync79123 +Node: budget79362 +Ref: #budget79484 +Node: chart79550 +Ref: #chart79667 +Node: check79738 +Ref: #check79840  End Tag Table diff --git a/hledger/hledger.txt b/hledger/hledger.txt index 6eb336e53..39c868621 100644 --- a/hledger/hledger.txt +++ b/hledger/hledger.txt @@ -806,22 +806,26 @@ COMMANDS accounts Show account names. Alias: a. - --tree show short account names, as a tree + --declared + show account names declared with account directives + + --posted + show account names posted to by transactions + + --tree show short account names and their parents, as a tree --flat show full account names, as a list (default) --drop=N in flat mode: omit N leading account name parts - This command lists all account names that are in use (ie, all the - accounts which have at least one transaction posting to them). With - query arguments, only matched account names are shown. - - It shows a flat list by default. With --tree, it uses indentation to - show the account hierarchy. - - In flat mode you can add --drop N to omit the first few account name - components. + This command lists account names, either declared with account direc- + tives (-declared), posted to (-posted), or both (default). With query + arguments, only matched account names and account names referenced by + matched postings are shown. It shows a flat list by default. With + --tree, it uses indentation to show the account hierarchy. In flat + mode you can add --drop N to omit the first few account name compo- + nents. Account names can be depth-clipped with --depth N or depth:N. Examples: diff --git a/hledger/hledger_commands.m4.md b/hledger/hledger_commands.m4.md index ef51f2137..8dc32e899 100644 --- a/hledger/hledger_commands.m4.md +++ b/hledger/hledger_commands.m4.md @@ -26,8 +26,14 @@ for each command: name, synopsis, description, examples. ## accounts Show account names. Alias: a. +`--declared` +: show account names declared with account directives + +`--posted` +: show account names posted to by transactions + `--tree` -: show short account names, as a tree +: show short account names and their parents, as a tree `--flat` : show full account names, as a list (default) @@ -35,15 +41,14 @@ Show account names. Alias: a. `--drop=N` : in flat mode: omit N leading account name parts -This command lists all account names that are in use (ie, all the -accounts which have at least one transaction posting to them). With -query arguments, only matched account names are shown. - +This command lists account names, either declared with account directives +(--declared), posted to (--posted), or both (default). +With query arguments, only matched account names and account names +referenced by matched postings are shown. It shows a flat list by default. With `--tree`, it uses indentation to show the account hierarchy. - -In flat mode you can add `--drop N` to omit the first few account name -components. +In flat mode you can add `--drop N` to omit the first few account name components. +Account names can be depth-clipped with `--depth N` or depth:N. Examples: