diff --git a/cmd/cli/config.go b/cmd/cli/config.go index 86a6c46..36165e7 100644 --- a/cmd/cli/config.go +++ b/cmd/cli/config.go @@ -17,4 +17,5 @@ type Config struct { } Compact bool GroupDate string + NoPercent bool } diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 599530e..55a3785 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -42,6 +42,7 @@ func Main() { fs.StringVar(&config.CPI, "cpi", "", "path to cpi") fs.StringVar(&config.GroupDate, "group-date", "^....-..-..", "date grouping") fs.IntVar(&config.CPIYear, "cpiy", 0, "use cpi to convert usd to this year's value") + fs.BoolVar(&config.NoPercent, "no-percent", false, "compute percent") if err := fs.Parse(os.Args[1:]); err != nil { panic(err) } @@ -146,25 +147,29 @@ func Main() { Normalize(cpiNormalizer, "9") cumulatives := make(ledger.Balances) - var sum float64 - for key := range balances { - if _, ok := cumulatives[key]; !ok { - cumulatives[key] = make(ledger.Balance) - } - for currency, val := range balances[key] { - if currency == ledger.USD { - cumulatives[key][currency] = val - sum += val - } else { - cumulatives[key][currency] = 0 + cumulativesFormat := "%s%.2f" + if !config.NoPercent { + var sum float64 + for key := range balances { + if _, ok := cumulatives[key]; !ok { + cumulatives[key] = make(ledger.Balance) + } + for currency, val := range balances[key] { + if currency == ledger.USD { + cumulatives[key][currency] = val + sum += val + } else { + cumulatives[key][currency] = 0 + } } } - } - for key := range cumulatives { - cumulatives[key][ledger.USD] = 100 * cumulatives[key][ledger.USD] / sum + for key := range cumulatives { + cumulatives[key][ledger.USD] = 100 * cumulatives[key][ledger.USD] / sum + } + cumulativesFormat = "%.0f%%" } - FPrintBalances(w, "", balances, cumulatives, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW, "%.0f%%") + FPrintBalances(w, "", balances, cumulatives, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW, cumulativesFormat) case "gra": // graph dateGrouping := "^[0-9]{4}-[0-9]{2}" if period := config.Query.Period; !period.Empty() { diff --git a/cmd/main.go b/cmd/main.go index 85b63cb..ed92e83 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -49,6 +49,7 @@ func main() { "--depth=1", "--usd", "-n", + "--no-percent", "bal", "^Bel", "^Zach", ) main()