WIP cmd/cli$ go run ../ cli $(printf " -f %s" $HOME/Sync/Core/ledger/eras/2022-/*.txt) -n -w ^Housey --depth 1 -usd bal
All checks were successful
cicd / ci (push) Successful in 1m32s

This commit is contained in:
Bel LaPointe
2025-04-03 21:39:36 -06:00
parent 697fc16b52
commit dd20f066a3
3 changed files with 18 additions and 9 deletions

View File

@@ -20,9 +20,10 @@ 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.StringVar(&config.Query.With, "w", "", "regexp for transactions")
fs.IntVar(&config.Query.Depth, "depth", 0, "depth grouping")
fs.BoolVar(&config.Query.Reverse, "r", false, "reverse printed accounts")
fs.BoolVar(&config.Query.Normalize, "n", false, "normalize with default normalizer")
fs.BoolVar(&config.Query.USDOnly, "usd", false, "filter to usd")
fs.BoolVar(&config.Query.NoExchanging, "no-exchanging", true, "omit currency exchanges")
fs.StringVar(&config.BPI, "bpi", "", "path to bpi")
if err := fs.Parse(os.Args[1:]); err != nil {
@@ -44,7 +45,7 @@ func Main() {
}
cmd := positional[0]
q, err := BuildQuery(positional[1:])
q, err := BuildQuery(config, positional[1:])
if err != nil {
panic(err)
}
@@ -93,7 +94,7 @@ func Main() {
KindaLike(q).
KindaGroup(group).
Nonzero()
FPrintBalances(os.Stdout, "", balances, nil)
FPrintBalances(os.Stdout, "", balances, nil, config.Query.USDOnly)
case "reg":
transactions := deltas.Transactions()
@@ -111,7 +112,7 @@ func Main() {
}
if shouldPrint {
fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description)
FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero())
FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero(), config.Query.USDOnly)
}
}
default:
@@ -119,7 +120,7 @@ func Main() {
}
}
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances) {
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly bool) {
keys := []string{}
for k := range balances {
keys = append(keys, k)
@@ -146,6 +147,9 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
if printableCurrency != "$" {
printableCurrency += " "
}
if usdOnly && printableCurrency != "$" {
continue
}
cumulative := balances[key][currency]
if balance, ok := cumulatives[key]; !ok {