-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
80 lines (67 loc) · 1.38 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"os"
"skrive/data"
"skrive/data/fs"
"skrive/log"
"skrive/startMenu"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
if len(os.Getenv("DEBUG")) > 0 {
f, err := tea.LogToFile("debug.log", "debug")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}
defer f.Close()
}
if parseErr := parse(); parseErr != nil {
printHelp(parseErr)
os.Exit(1)
} else if *helpFlag {
printHelp(nil)
os.Exit(0)
}
data.ApplicationStorage = initialiseStorageInterface()
if subcommand != nil {
handleSubcommands()
}
var model tea.Model
if subcommand != nil && *subcommand == "log" {
model, _ = log.InitializeModel(func() (tea.Model, tea.Cmd) {
return model, tea.Quit
})
} else {
model = startMenu.InitializeModel()
}
_, err := tea.
NewProgram(model).
Run()
exitIfError(err)
}
func initialiseStorageInterface() data.Storage {
// There is currently only one type of storage
p, err := fs.GetPath(*fileArg)
exitIfError(err)
return fs.FsStorage{Path: *p}
}
func handleSubcommands() {
switch *subcommand {
case "log":
if len(positionalArguments) == 0 {
// Handled in Bubbletea initialization code
return
}
exitIfError(log.Invoke(positionalArguments))
}
os.Exit(0)
}
func exitIfError(err error) {
if err == nil {
return
}
fmt.Println("Undskyld! Something went wrong >w< here it is: %v", err)
os.Exit(1)
}