-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (56 loc) · 1.7 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"github.com/lieut-data/go-moneywell/api"
"github.com/lieut-data/go-moneywell/internal/cli"
_ "github.com/mattn/go-sqlite3"
)
func main() {
var verbose bool
var moneywellPath, list, tag, bucket, account string
flag.BoolVar(&verbose, "verbose", false, "be more verbose")
flag.StringVar(&moneywellPath, "file", "", "the path to the MoneyWell document")
flag.StringVar(&list, "list", "", "list the given entity")
flag.StringVar(&account, "account", "", "the bucket by which to filter transactions")
flag.StringVar(&bucket, "bucket", "", "the bucket by which to filter transactions")
flag.StringVar(&tag, "tag", "", "the tag by which to filter transactions")
flag.Parse()
if moneywellPath == "" {
fmt.Println("required: path to moneywell document")
return
}
database, err := api.OpenDocument(moneywellPath)
if err != nil {
fmt.Printf("failed to open database: %v\n", err)
return
}
defer func() {
if err := database.Close(); err != nil {
fmt.Printf("failed to close database: %v\n", err)
return
}
}()
switch list {
case "account-groups":
err = cli.ListAccountGroups(database, verbose)
case "accounts":
err = cli.ListAccounts(database, verbose)
case "bucket-groups":
err = cli.ListBucketGroups(database, verbose)
case "buckets":
err = cli.ListBuckets(database, verbose)
case "tags":
err = cli.ListTags(database, verbose)
case "transactions":
err = cli.ListTransactions(database, account, bucket, tag, verbose)
case "recurrence-rules":
err = cli.ListRecurrenceRules(database, verbose)
case "spending-plan":
err = cli.ListSpendingPlanEvents(database, bucket, verbose)
}
if err != nil {
fmt.Printf("cli failed: %v\n", err)
return
}
}