WIP cmd/cli$ go run ../ cli $(printf " -f %s" $HOME/Sync/Core/ledger/eras/2022-/*.txt) -n -w ^Housey --depth 1 -usd bal
cicd / ci (push) Successful in 1m32s
Details
cicd / ci (push) Successful in 1m32s
Details
parent
697fc16b52
commit
dd20f066a3
|
|
@ -8,8 +8,9 @@ type Config struct {
|
|||
Sort string
|
||||
NoRounding bool
|
||||
Depth int
|
||||
Reverse bool
|
||||
With string
|
||||
NoExchanging bool
|
||||
Normalize bool
|
||||
USDOnly bool
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
type Query struct{}
|
||||
|
||||
func BuildQuery(args args) (ledger.Like, error) {
|
||||
func BuildQuery(config Config, args args) (ledger.Like, error) {
|
||||
var result ledger.Like
|
||||
var err error
|
||||
func() {
|
||||
|
|
@ -18,12 +18,12 @@ func BuildQuery(args args) (ledger.Like, error) {
|
|||
err = fmt.Errorf("panicked: %v", err)
|
||||
}
|
||||
}()
|
||||
result, err = buildQuery(args)
|
||||
result, err = buildQuery(config, args)
|
||||
}()
|
||||
return result, err
|
||||
}
|
||||
|
||||
func buildQuery(args args) (ledger.Like, error) {
|
||||
func buildQuery(config Config, args args) (ledger.Like, error) {
|
||||
likeName := func(s string) ledger.Like {
|
||||
return ledger.LikeName(s)
|
||||
}
|
||||
|
|
@ -71,6 +71,10 @@ func buildQuery(args args) (ledger.Like, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if config.Query.With != "" {
|
||||
like = andLike(like, ledger.LikeWith(config.Query.With))
|
||||
}
|
||||
|
||||
return like, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue