reg -c prints DATE FULL:ACC DELTA (BAL)
All checks were successful
cicd / ci (push) Successful in 46s

This commit is contained in:
bel
2025-04-06 11:03:53 -06:00
parent 84bbda1031
commit 9646356d7f
2 changed files with 15 additions and 5 deletions

View File

@@ -13,4 +13,5 @@ type Config struct {
Normalize bool
USDOnly bool
}
Compact bool
}

View File

@@ -23,6 +23,7 @@ func Main() {
fs.Var(&config.Query.Period, "period", "period")
fs.StringVar(&config.Query.Sort, "S", "", "sort ie date")
fs.BoolVar(&config.Query.NoRounding, "no-rounding", false, "no rounding")
fs.BoolVar(&config.Compact, "c", false, "reg entries oneline")
fs.StringVar(&config.Query.With, "w", "", "regexp for transactions")
fs.IntVar(&config.Query.Depth, "depth", 0, "depth grouping")
fs.BoolVar(&config.Query.Normalize, "n", false, "normalize with default normalizer")
@@ -104,7 +105,7 @@ func Main() {
KindaLike(q).
KindaGroup(group).
Nonzero()
FPrintBalances(w, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"))
FPrintBalances(w, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false)
case "reg":
transactions := deltas.Transactions()
cumulative := make(ledger.Balances)
@@ -123,8 +124,7 @@ func Main() {
if shouldPrint {
cumulative.PushAll(balances)
cumulative = cumulative.Nonzero()
fmt.Fprintf(w, "%s\t%s\n", transaction[0].Date, transaction[0].Description)
FPrintBalances(w, "\t\t", balances, cumulative, config.Query.USDOnly, config.Query.Normalize, transaction[0].Date)
FPrintBalancesFor(transaction[0].Description, w, "\t\t", balances, cumulative, config.Query.USDOnly, config.Query.Normalize, transaction[0].Date, config.Compact)
}
}
default:
@@ -132,7 +132,16 @@ func Main() {
}
}
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string) {
func FPrintBalancesFor(description string, w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string, compact bool) {
if compact {
FPrintBalances(w, date+"\t", balances, cumulatives, usdOnly, normalized, date, compact)
} else {
fmt.Fprintf(w, "%s\t%s\n", date, description)
FPrintBalances(w, linePrefix, balances, cumulatives, usdOnly, normalized, date, compact)
}
}
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string, fullKey bool) {
maxes := map[ledger.Currency]float64{}
keys := []string{}
for k, v := range balances {
@@ -160,7 +169,7 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
}
for i, key := range keys {
printableKey := key
if i > 0 {
if !fullKey && i > 0 {
j := 0
n := len(keys[i])
if n2 := len(keys[i-1]); n2 < n {