/
main.go
49 lines (41 loc) · 1.22 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
package main
import (
"fmt"
"io/ioutil"
"github.com/meisterluk/personal-accounting-go/cli"
"github.com/meisterluk/personal-accounting-go/storage"
"github.com/meisterluk/personal-accounting-go/types"
flag "github.com/ogier/pflag"
yaml "gopkg.in/yaml.v2"
)
// ReadConfig read a configuration from a given filepath
// and writes the settings to the given Application instance
func ReadConfig(filepath string, app *types.Application) {
content, err := ioutil.ReadFile(filepath)
if err != nil {
panic(fmt.Sprintf("Could not read configuration file: %s", filepath))
}
yaml.Unmarshal(content, &app)
}
func printHeader(app *types.Application) {
fmt.Println("personal-accounting-go v0.1")
fmt.Println()
fmt.Printf("1. configuration settings for %s have been read\n", app.User)
fmt.Println("2. I will ask you to provide transaction information")
fmt.Println()
}
func main() {
configFile := flag.StringP("config", "c", "accounting.yml", "configuration file")
flag.Parse()
app := types.Application{}
ReadConfig(*configFile, &app)
var store types.Storage
if app.StorageType == "xml" {
store = storage.XMLStorage{app.XMLFilepath}
}
printHeader(&app)
err := cli.MainLoop(&app, &store)
if err != nil {
panic(err.Error())
}
}