~mendelmaleh/pfin

64dd8af6f07b145354c6dd151d781d83973d7064 — Mendel Elmaleh 26 days ago 1d8e439
Add option to sort newest first in cmd/pfin
1 files changed, 12 insertions(+), 4 deletions(-)

M cmd/pfin/main.go
M cmd/pfin/main.go => cmd/pfin/main.go +12 -4
@@ 18,8 18,10 @@ func main() {
	// flags
	opts := struct {
		parser *string
		new    *bool
	}{
		flag.String("parser", "", "parser to use for files"),
		flag.Bool("new", false, "sort transactions new to old"),
	}

	flag.Parse()


@@ 71,10 73,16 @@ func main() {

	}

	// sort oldest to newest
	sort.SliceStable(txns, func(i, j int) bool {
		return txns[i].Date().Before(txns[j].Date())
	})
	// sort transactions
	if *opts.new {
		sort.SliceStable(txns, func(i, j int) bool {
			return txns[i].Date().After(txns[j].Date())
		})
	} else {
		sort.SliceStable(txns, func(i, j int) bool {
			return txns[i].Date().Before(txns[j].Date())
		})
	}

	// csv
	w := csv.NewWriter(os.Stdout)