impl cli reg depth
cicd / ci (push) Successful in 1m24s Details

main
Bel LaPointe 2025-02-21 14:47:30 -07:00
parent a1631019f0
commit ed0ce83556
1 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"os" "os"
"slices" "slices"
"strings"
"gogs.inhome.blapointe.com/ana-ledger/src/ledger" "gogs.inhome.blapointe.com/ana-ledger/src/ledger"
) )
@ -59,9 +60,15 @@ func Main() {
) )
} }
pattern := ".*"
if depth := config.Query.Depth; depth > 0 { if depth := config.Query.Depth; depth > 0 {
panic(depth) pattern = ""
for i := 0; i < depth; i++ {
pattern += "[^:]*:"
} }
pattern = strings.Trim(pattern, ":")
}
group := ledger.GroupName(pattern)
switch cmd[:3] { switch cmd[:3] {
case "bal": case "bal":
@ -80,7 +87,7 @@ func Main() {
transactions := deltas.Transactions() transactions := deltas.Transactions()
for i, transaction := range transactions { for i, transaction := range transactions {
balances := ledger.Deltas(transaction).Like(q).Balances() balances := ledger.Deltas(transaction).Like(q).Group(group).Balances()
shouldPrint := false shouldPrint := false
shouldPrint = shouldPrint || len(balances) > 2 shouldPrint = shouldPrint || len(balances) > 2
if config.Query.NoExchanging { if config.Query.NoExchanging {
@ -93,7 +100,7 @@ func Main() {
} }
if shouldPrint { if shouldPrint {
fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description) fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description)
FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Balances()) FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances())
} }
} }
default: default: