From 81df8fbdc200fd6ecfca6b04a29c451124bfa885 Mon Sep 17 00:00:00 2001 From: Martin Strobel Date: Sun, 10 Mar 2019 23:11:32 -0700 Subject: [PATCH] Alphabetize budgets when print balances (#12) --- cmd/balance.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/balance.go b/cmd/balance.go index 5bbe147..f9b7a65 100644 --- a/cmd/balance.go +++ b/cmd/balance.go @@ -22,6 +22,7 @@ import ( "os" "path" "path/filepath" + "sort" "time" "github.com/marstr/envelopes" @@ -156,7 +157,15 @@ func writeBudgetBalances(_ context.Context, output io.Writer, budget envelopes.B if err != nil { return } - for name, child := range budget.Children { + + childNames := make([]string, 0, len(budget.Children)) + for name := range budget.Children { + childNames = append(childNames, name) + } + sort.Strings(childNames) + + for _, name := range childNames { + child := budget.Children[name] _, err = fmt.Fprintf(output, "\t%s: %s\n", name, child.RecursiveBalance()) if err != nil { return