{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module Hledger.Cli.Commands.Accounts (
accountsmode
,accounts
) where
import Data.List
import Data.Map qualified as M
import Data.Text qualified as T
import System.Console.CmdArgs.Explicit as C
import Hledger
import Hledger.Cli.CliOptions
import Hledger.Cli.Utils (writeOutputWithTitle)
accountsmode :: Mode RawOpts
accountsmode = CommandHelpStr
-> [Flag RawOpts]
-> [(CommandHelpStr, [Flag RawOpts])]
-> [Flag RawOpts]
-> ([Arg RawOpts], Maybe (Arg RawOpts))
-> Mode RawOpts
hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Accounts.txt")
(
[[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"used",CommandHelpStr
"u"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"used") CommandHelpStr
"list accounts used"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"declared",CommandHelpStr
"d"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"declared") CommandHelpStr
"list accounts declared"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"undeclared"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"undeclared") CommandHelpStr
"list accounts used but not declared"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"unused"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"unused") CommandHelpStr
"list accounts declared but not used"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"find"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"find") CommandHelpStr
"list the first account matched by the first argument (a case-insensitive infix regexp)"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"directives"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"directives") CommandHelpStr
"show as account directives, for use in journals"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"locations"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"locations") CommandHelpStr
"also show where accounts were declared, or first used"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"types"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"types") CommandHelpStr
"also show account types when known"
,[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"show-aliases"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"show-aliases") CommandHelpStr
"also show account aliases declared with alias: tags"
]
[Flag RawOpts] -> [Flag RawOpts] -> [Flag RawOpts]
forall a. [a] -> [a] -> [a]
++ Bool -> [Flag RawOpts]
flattreeflags Bool
False [Flag RawOpts] -> [Flag RawOpts] -> [Flag RawOpts]
forall a. [a] -> [a] -> [a]
++
[[CommandHelpStr]
-> Update RawOpts
-> CommandHelpStr
-> CommandHelpStr
-> Flag RawOpts
forall a.
[CommandHelpStr]
-> Update a -> CommandHelpStr -> CommandHelpStr -> Flag a
flagReq [CommandHelpStr
"drop"] (\CommandHelpStr
s RawOpts
opts -> RawOpts -> Either CommandHelpStr RawOpts
forall a b. b -> Either a b
Right (RawOpts -> Either CommandHelpStr RawOpts)
-> RawOpts -> Either CommandHelpStr RawOpts
forall a b. (a -> b) -> a -> b
$ CommandHelpStr -> CommandHelpStr -> RawOpts -> RawOpts
setopt CommandHelpStr
"drop" CommandHelpStr
s RawOpts
opts) CommandHelpStr
"N" CommandHelpStr
"flat mode: omit N leading account name parts"]
)
[(CommandHelpStr, [Flag RawOpts])]
cligeneralflagsgroups1
([Flag RawOpts]
hiddenflags [Flag RawOpts] -> [Flag RawOpts] -> [Flag RawOpts]
forall a. [a] -> [a] -> [a]
++
[[CommandHelpStr]
-> (RawOpts -> RawOpts) -> CommandHelpStr -> Flag RawOpts
forall a. [CommandHelpStr] -> (a -> a) -> CommandHelpStr -> Flag a
flagNone [CommandHelpStr
"positions"] (CommandHelpStr -> RawOpts -> RawOpts
setboolopt CommandHelpStr
"locations") CommandHelpStr
"deprecated, use --locations instead"
])
([], Arg RawOpts -> Maybe (Arg RawOpts)
forall a. a -> Maybe a
Just (Arg RawOpts -> Maybe (Arg RawOpts))
-> Arg RawOpts -> Maybe (Arg RawOpts)
forall a b. (a -> b) -> a -> b
$ CommandHelpStr -> Arg RawOpts
argsFlag CommandHelpStr
"[QUERY..]")
accounts :: CliOpts -> Journal -> IO ()
accounts :: CliOpts -> Journal -> IO ()
accounts opts :: CliOpts
opts@CliOpts{rawopts_ :: CliOpts -> RawOpts
rawopts_=RawOpts
rawopts, reportspec_ :: CliOpts -> ReportSpec
reportspec_=ReportSpec{_rsQuery :: ReportSpec -> Query
_rsQuery=Query
query,_rsReportOpts :: ReportSpec -> ReportOpts
_rsReportOpts=ReportOpts
ropts}} Journal
j = do
let tree :: Bool
tree = ReportOpts -> Bool
tree_ ReportOpts
ropts
directives :: Bool
directives = CommandHelpStr -> RawOpts -> Bool
boolopt CommandHelpStr
"directives" RawOpts
rawopts
locations :: Bool
locations = CommandHelpStr -> RawOpts -> Bool
boolopt CommandHelpStr
"locations" RawOpts
rawopts
types :: Bool
types = CommandHelpStr -> RawOpts -> Bool
boolopt CommandHelpStr
"types" RawOpts
rawopts
showaliases :: Bool
showaliases = CommandHelpStr -> RawOpts -> Bool
boolopt CommandHelpStr
"show-aliases" RawOpts
rawopts
aliasq :: Query -> Query
aliasq = if Bool
showaliases then (Query -> Query) -> Query -> Query
transformQuery Query -> Query
matchAliasToo else Query -> Query
forall a. a -> a
id
where
matchAliasToo :: Query -> Query
matchAliasToo (Acct Regexp
r) = [Query] -> Query
Or [Regexp -> Query
Acct Regexp
r, Regexp -> Maybe Regexp -> Query
Tag (Text -> Regexp
toRegexCI' Text
"^alias$") (Regexp -> Maybe Regexp
forall a. a -> Maybe a
Just Regexp
r)]
matchAliasToo Query
q = Query
q
nodepthq :: Query
nodepthq = CommandHelpStr -> Query -> Query
forall a. Show a => CommandHelpStr -> a -> a
dbg4 CommandHelpStr
"nodepthq" (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ Query -> Query
aliasq (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ (Query -> Bool) -> Query -> Query
filterQuery (Bool -> Bool
not (Bool -> Bool) -> (Query -> Bool) -> Query -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query -> Bool
queryIsDepth) Query
query
acctq :: Query
acctq = CommandHelpStr -> Query -> Query
forall a. Show a => CommandHelpStr -> a -> a
dbg4 CommandHelpStr
"acctq" (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ Query -> Query
aliasq (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ (Query -> Bool) -> Query -> Query
filterQuery Query -> Bool
queryIsAcct Query
query
dep :: DepthSpec
dep = CommandHelpStr -> DepthSpec -> DepthSpec
forall a. Show a => CommandHelpStr -> a -> a
dbg4 CommandHelpStr
"depth" (DepthSpec -> DepthSpec) -> DepthSpec -> DepthSpec
forall a b. (a -> b) -> a -> b
$ Query -> DepthSpec
queryDepth (Query -> DepthSpec) -> Query -> DepthSpec
forall a b. (a -> b) -> a -> b
$ (Query -> Bool) -> Query -> Query
filterQuery Query -> Bool
queryIsDepth Query
query
matchedused :: [Text]
matchedused = CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg5 CommandHelpStr
"matchedused" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
forall a. Eq a => [a] -> [a]
nub ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (Posting -> Text) -> [Posting] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Posting -> Text
paccount ([Posting] -> [Text]) -> [Posting] -> [Text]
forall a b. (a -> b) -> a -> b
$ Journal -> [Posting]
journalPostings (Journal -> [Posting]) -> Journal -> [Posting]
forall a b. (a -> b) -> a -> b
$
Query -> Journal -> Journal
filterJournalPostings Query
nodepthq (Journal -> Journal) -> Journal -> Journal
forall a b. (a -> b) -> a -> b
$ Journal -> Journal
journalPostingsKeepAccountTagsOnly Journal
j
matcheddeclared :: [Text]
matcheddeclared = CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg5 CommandHelpStr
"matcheddeclared" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
[Text] -> [Text]
forall a. Eq a => [a] -> [a]
nub ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
(Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Text -> Maybe AccountType)
-> (Text -> [Tag]) -> Query -> Text -> Bool
matchesAccountExtra (Journal -> Text -> Maybe AccountType
journalAccountType Journal
j) (Journal -> Text -> [Tag]
journalInheritedAccountTags Journal
j) Query
nodepthq) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
((Text, AccountDeclarationInfo) -> Text)
-> [(Text, AccountDeclarationInfo)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, AccountDeclarationInfo) -> Text
forall a b. (a, b) -> a
fst ([(Text, AccountDeclarationInfo)] -> [Text])
-> [(Text, AccountDeclarationInfo)] -> [Text]
forall a b. (a -> b) -> a -> b
$ Journal -> [(Text, AccountDeclarationInfo)]
jdeclaredaccounts Journal
j
matchedundeclared :: [Text]
matchedundeclared = CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg5 CommandHelpStr
"matchedundeclared" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
forall a. Eq a => [a] -> [a]
nub ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text]
matchedused [Text] -> [Text] -> [Text]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Text]
alldeclared
matchedunused :: [Text]
matchedunused = CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg5 CommandHelpStr
"matchedunused" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
forall a. Eq a => [a] -> [a]
nub ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text]
matcheddeclared [Text] -> [Text] -> [Text]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Text]
allused
allused :: [Text]
allused = (Posting -> Text) -> [Posting] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Posting -> Text
paccount ([Posting] -> [Text]) -> [Posting] -> [Text]
forall a b. (a -> b) -> a -> b
$ Journal -> [Posting]
journalPostings Journal
j
alldeclared :: [Text]
alldeclared = ((Text, AccountDeclarationInfo) -> Text)
-> [(Text, AccountDeclarationInfo)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, AccountDeclarationInfo) -> Text
forall a b. (a, b) -> a
fst ([(Text, AccountDeclarationInfo)] -> [Text])
-> [(Text, AccountDeclarationInfo)] -> [Text]
forall a b. (a -> b) -> a -> b
$ Journal -> [(Text, AccountDeclarationInfo)]
jdeclaredaccounts Journal
j
found :: Text
found = CommandHelpStr -> Text -> Text
forall a. Show a => CommandHelpStr -> a -> a
dbg5 CommandHelpStr
"matchedacct" (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ RawOpts -> CommandHelpStr -> [Text] -> Text
findMatchedByArgument RawOpts
rawopts CommandHelpStr
"account" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Journal -> [Text]
journalAccountNamesDeclaredOrImplied Journal
j
matchedall :: [Text]
matchedall = [Text]
matcheddeclared [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text]
matchedused
accts :: [Text]
accts = CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg5 CommandHelpStr
"accts to show" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
case CliOpts -> Maybe DeclarablesSelector
declarablesSelectorFromOpts CliOpts
opts of
Maybe DeclarablesSelector
Nothing -> [Text]
matchedall
Just DeclarablesSelector
Used -> [Text]
matchedused
Just DeclarablesSelector
Declared -> [Text]
matcheddeclared
Just DeclarablesSelector
Undeclared -> [Text]
matchedundeclared
Just DeclarablesSelector
Unused -> [Text]
matchedunused
Just DeclarablesSelector
FindFirst -> [Text
found]
sortedaccts :: [Text]
sortedaccts = Journal -> Bool -> [Text] -> [Text]
sortAccountNamesByDeclaration Journal
j Bool
tree [Text]
accts
acctswithparents :: [Text]
acctswithparents =
if Bool
tree
then CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg4 CommandHelpStr
"acctswithparents" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
Journal -> Bool -> [Text] -> [Text]
sortAccountNamesByDeclaration Journal
j Bool
tree ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
[Text] -> [Text]
expandAccountNames [Text]
sortedaccts
else [Text]
sortedaccts
clippedaccts :: [Text]
clippedaccts =
CommandHelpStr -> [Text] -> [Text]
forall a. Show a => CommandHelpStr -> a -> a
dbg4 CommandHelpStr
"clippedaccts" ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
(if Bool
tree then [Text] -> [Text]
forall a. a -> a
id else (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Text -> Maybe AccountType)
-> (Text -> [Tag]) -> Query -> Text -> Bool
matchesAccountExtra (Journal -> Text -> Maybe AccountType
journalAccountType Journal
j) (Journal -> Text -> [Tag]
journalInheritedAccountTags Journal
j) Query
acctq)) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
[Text] -> [Text]
forall a. Eq a => [a] -> [a]
nub ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
(Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
(Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (DepthSpec -> Text -> Text
clipAccountName DepthSpec
dep) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
[Text]
acctswithparents
let
showKeyword :: Text
showKeyword = if Bool
directives then Text
"account " else Text
""
showName :: Text -> Text
showName Text
a = case ReportOpts -> AccountListMode
accountlistmode_ ReportOpts
ropts of
AccountListMode
ALTree -> Text
indent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
accountLeafName Text
droppedName
AccountListMode
ALFlat -> Text
droppedName
where
indent :: Text
indent = Int -> Text -> Text
T.replicate (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Text -> Int
accountNameLevel Text
a Int -> Int -> Int
forall a. Num a => a -> a -> a
- ReportOpts -> Int
drop_ ReportOpts
ropts) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)) Text
" "
droppedName :: Text
droppedName = Int -> Text -> Text
accountNameDrop (ReportOpts -> Int
drop_ ReportOpts
ropts) Text
a
showComment :: Text -> Text
showComment Text
a = case [Text]
typeitem [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text]
aliasitems [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text]
locationitem of
[] -> Text
""
[Text]
items -> Text -> Text
pad Text
a Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" ; " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", " [Text]
items
where
typeitem :: [Text]
typeitem = [Text
"type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CommandHelpStr -> Text
T.pack (AccountType -> CommandHelpStr
forall a. Show a => a -> CommandHelpStr
show AccountType
t) | Bool
types, Just AccountType
t <- [Journal -> Text -> Maybe AccountType
journalAccountType Journal
j Text
a]]
aliasitems :: [Text]
aliasitems = [Text
"alias: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
v | Bool
directives Bool -> Bool -> Bool
|| Bool
showaliases, (Text
n, Text
v) <- Journal -> Text -> [Tag]
journalAccountTags Journal
j Text
a, Text -> Text
T.toLower Text
n Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"alias"]
locationitem :: [Text]
locationitem
| Bool
locations = [case Text
-> [(Text, AccountDeclarationInfo)] -> Maybe AccountDeclarationInfo
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
a ([(Text, AccountDeclarationInfo)] -> Maybe AccountDeclarationInfo)
-> [(Text, AccountDeclarationInfo)] -> Maybe AccountDeclarationInfo
forall a b. (a -> b) -> a -> b
$ Journal -> [(Text, AccountDeclarationInfo)]
jdeclaredaccounts Journal
j of
Just AccountDeclarationInfo
adi -> Text
"declared at " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CommandHelpStr -> Text
T.pack (SourcePos -> CommandHelpStr
sourcePosFileLine (SourcePos -> CommandHelpStr) -> SourcePos -> CommandHelpStr
forall a b. (a -> b) -> a -> b
$ AccountDeclarationInfo -> SourcePos
adisourcepos AccountDeclarationInfo
adi) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
", overall declaration order " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CommandHelpStr -> Text
T.pack (Int -> CommandHelpStr
forall a. Show a => a -> CommandHelpStr
show (Int -> CommandHelpStr) -> Int -> CommandHelpStr
forall a b. (a -> b) -> a -> b
$ AccountDeclarationInfo -> Int
adideclarationorder AccountDeclarationInfo
adi)
Maybe AccountDeclarationInfo
Nothing -> Text
"undeclared" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> (Text -> Text) -> Maybe Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (Text
", first used at " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
a Map Text Text
firstuses)]
| Bool
otherwise = []
firstuses :: Map Text Text
firstuses = (Text -> Text -> Text) -> [Tag] -> Map Text Text
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
M.fromListWith (\Text
_ Text
earlier -> Text
earlier)
[ (Posting -> Text
paccount Posting
p, CommandHelpStr -> Text
T.pack (CommandHelpStr -> Text) -> CommandHelpStr -> Text
forall a b. (a -> b) -> a -> b
$ CommandHelpStr
f CommandHelpStr -> CommandHelpStr -> CommandHelpStr
forall a. [a] -> [a] -> [a]
++ CommandHelpStr
":" CommandHelpStr -> CommandHelpStr -> CommandHelpStr
forall a. [a] -> [a] -> [a]
++ Int -> CommandHelpStr
forall a. Show a => a -> CommandHelpStr
show Int
l)
| Transaction
t <- Journal -> [Transaction]
jtxns Journal
j
, (Int
i,Posting
p) <- [Int] -> [Posting] -> [(Int, Posting)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] ([Posting] -> [(Int, Posting)]) -> [Posting] -> [(Int, Posting)]
forall a b. (a -> b) -> a -> b
$ Transaction -> [Posting]
tpostings Transaction
t
, let (CommandHelpStr
f, Int
l, Maybe (Int, Maybe Int)
_, Text
_) = Transaction
-> Int
-> Maybe (Int, Maybe Int)
-> (CommandHelpStr, Int, Maybe (Int, Maybe Int), Text)
makePostingErrorExcerptByIndex Transaction
t Int
i Maybe (Int, Maybe Int)
forall a. Maybe a
Nothing
]
pad :: Text -> Text
pad Text
a = Int -> Text -> Text
T.replicate (Int
maxwidth Int -> Int -> Int
forall a. Num a => a -> a -> a
- Text -> Int
T.length (Text -> Text
showName Text
a)) Text
" "
maxwidth :: Int
maxwidth = [Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (Text -> Int) -> [Text] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Int
T.length (Text -> Int) -> (Text -> Text) -> Text -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
showName) [Text]
clippedaccts
CliOpts -> Text -> IO ()
writeOutputWithTitle CliOpts
opts (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unlines [Text
showKeyword Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
showName Text
a Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
showComment Text
a | Text
a <- [Text]
clippedaccts]