Skip to content

Commit

Permalink
fix: print accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Nov 3, 2023
1 parent aa61bc8 commit 42d537c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions ledger/cmd/printAccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@ var accountsCmd = &cobra.Command{
}

balances := ledger.GetBalances(generalLedger, args)
var currentAccount string
if len(balances) > 0 {
currentAccount = balances[0].Name
}
for _, account := range balances[1:] {
if accountLeavesOnly && !strings.HasPrefix(account.Name, currentAccount) {
fmt.Println(currentAccount)
} else if accountMatchDepth && filterDepth == strings.Count(currentAccount, ":") {
fmt.Println(currentAccount)
} else if !accountLeavesOnly && !accountMatchDepth {
fmt.Println(currentAccount)

children := make(map[string]int)
for _, acc := range balances {
if i := strings.LastIndex(acc.Name, ":"); i >= 0 {
children[acc.Name[:i]]++
}
currentAccount = account.Name
}
if accountMatchDepth && filterDepth == strings.Count(currentAccount, ":") {
fmt.Println(currentAccount)
} else if !accountMatchDepth {
fmt.Println(currentAccount)

for _, acc := range balances {
match := true
if accountLeavesOnly && children[acc.Name] > 0 {
match = false
}
if accountMatchDepth && filterDepth != strings.Count(acc.Name, ":") {
match = false
}
if match {
fmt.Println(acc.Name)
}
}
},
}
Expand Down

0 comments on commit 42d537c

Please sign in to comment.