show proper error message if ledger is not installed

This commit is contained in:
Anantha Kumaran 2022-04-20 09:03:09 +05:30
parent d3f9160f03
commit 5a58b5a508
1 changed files with 7 additions and 2 deletions

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/csv"
"log"
log "github.com/sirupsen/logrus"
"os/exec"
"strconv"
"time"
@ -15,11 +15,16 @@ import (
func Parse(journalPath string) ([]*posting.Posting, error) {
var postings []*posting.Posting
_, err := exec.LookPath("ledger")
if err != nil {
log.Fatal(err)
}
command := exec.Command("ledger", "-f", journalPath, "csv", "--csv-format", "%(quoted(date)),%(quoted(payee)),%(quoted(display_account)),%(quoted(commodity(scrub(display_amount)))),%(quoted(quantity(scrub(display_amount)))),%(quoted(to_int(scrub(market(amount,date)))))\n")
var output, error bytes.Buffer
command.Stdout = &output
command.Stderr = &error
err := command.Run()
err = command.Run()
if err != nil {
log.Fatal(error.String())
return nil, err