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

main
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 Normalize bool
USDOnly bool USDOnly bool
} }
Compact bool
} }

View File

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