From 5ffe1d765645c0c15af15e0c5929205a87af0213 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Tue, 7 Jul 2020 23:02:54 +1000 Subject: [PATCH] cli: Allow --drop in account command in tree mode. --- hledger/Hledger/Cli/Commands/Accounts.hs | 10 ++++++---- tests/accounts.test | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Accounts.hs b/hledger/Hledger/Cli/Commands/Accounts.hs index fc8e2ad06..20fba215a 100644 --- a/hledger/Hledger/Cli/Commands/Accounts.hs +++ b/hledger/Hledger/Cli/Commands/Accounts.hs @@ -83,7 +83,9 @@ accounts CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do -- 4. print what remains as a list or tree, maybe applying --drop in the former case mapM_ (T.putStrLn . render) clippedaccts where - render a - | tree_ ropts = T.replicate (2 * (accountNameLevel a - 1)) " " <> accountLeafName a - | otherwise = accountNameDrop (drop_ ropts) a - + render a = case accountlistmode_ ropts of + ALTree -> T.replicate indent " " <> accountLeafName droppedName + ALFlat -> droppedName + where + indent = 2 * (max 0 (accountNameLevel a - drop_ ropts) - 1) + droppedName = accountNameDrop (drop_ ropts) a diff --git a/tests/accounts.test b/tests/accounts.test index 55066e2d8..1bc07cbbd 100644 --- a/tests/accounts.test +++ b/tests/accounts.test @@ -18,6 +18,17 @@ a aa >= +# drop in flat mode +$ hledger -f - accounts --flat --drop 1 +... +aa +>= +# drop in tree mode +$ hledger -f - accounts --tree --drop 1 +... +aa +>= + # filtering transactions by tag $ hledger -f - accounts tag:foo a:aa