-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (44 loc) · 1.24 KB
/
Copy pathmain.go
File metadata and controls
54 lines (44 loc) · 1.24 KB
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
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/noma4i/westpac-cli/api"
"github.com/noma4i/westpac-cli/utils"
"github.com/noma4i/westpac-cli/views"
)
func main() {
debug := flag.Bool("debug", false, "Enable debug logging to ~/.westpac/debug.log")
mask := flag.Bool("mask", false, "Mask account names and descriptions (keep amounts visible)")
flag.Parse()
utils.MaskMode = *mask
var debugLog func(string)
if *debug {
logDir, _ := api.ConfigDir()
os.MkdirAll(logDir, 0700)
logPath := filepath.Join(logDir, "debug.log")
f, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
if err != nil {
log.Fatalf("Cannot open log file %s: %v", logPath, err)
}
defer f.Close()
fmt.Fprintf(f, "\n=== Session started %s ===\n", time.Now().Format(time.RFC3339))
debugLog = func(msg string) {
fmt.Fprintf(f, "[%s] %s\n", time.Now().Format("15:04:05.000"), msg)
}
fmt.Fprintf(os.Stderr, "Debug log: %s\n", logPath)
}
client, err := api.NewClient("", *debug, debugLog)
if err != nil {
log.Fatal(err)
}
app := views.NewAppModel(client)
p := tea.NewProgram(app, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}