-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnose.go
50 lines (39 loc) · 1.1 KB
/
diagnose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package doctor
import (
"fmt"
"github.com/pkg/errors"
"github.com/lieut-data/go-moneywell/api"
_ "github.com/mattn/go-sqlite3"
)
// Diagnose analyzes the given MoneyWell document for potential issues.
func Diagnose(moneywellPath string) error {
database, err := api.OpenDocument(moneywellPath)
if err != nil {
return errors.Wrapf(err, "failed to open %s", moneywellPath)
}
defer database.Close()
settings, err := api.GetSettings(database)
if err != nil {
return errors.Wrap(err, "failed to get settings")
}
accounts, err := api.GetAccounts(database)
if err != nil {
return errors.Wrap(err, "failed to get accounts")
}
transactions, err := api.GetTransactions(database)
if err != nil {
return errors.Wrap(err, "failed to get transactions")
}
problematicTransactions, err := GetProblematicTransactions(
settings,
accounts,
transactions,
)
if err != nil {
return errors.Wrap(err, "failed to query for problematic transactions")
}
for _, problematicTransaction := range problematicTransactions {
fmt.Printf("WARNING: %s\n", problematicTransaction.Description)
}
return nil
}