-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (46 loc) · 1.17 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
package main
import (
"fmt"
"github.com/mwstobo/rank/config"
"github.com/mwstobo/rank/input"
"github.com/mwstobo/rank/ranker"
"github.com/mwstobo/rank/rankings"
"github.com/mwstobo/rank/store"
"github.com/mwstobo/rank/ui"
"os"
)
func main() {
err := config.ParseConfig()
if err == config.Help {
os.Exit(0)
} else if err != nil {
fmt.Printf("Error parsing config: %v\n", err)
os.Exit(1)
}
storage := store.NewJsonStorage(config.Filename)
rankingSlice, err := storage.Import()
if err != nil {
fmt.Printf("Error importing ranking file: %v\n", err)
os.Exit(1)
}
stdinInput := input.NewStdinUserInput()
ranking := rankings.NewArrayRanking(rankingSlice)
ranker := ranker.NewRanker(ranking, stdinInput)
if config.Ui == config.INTERACTIVE {
app := ui.NewInteractiveApp(ranker, storage, stdinInput)
app.Run()
} else {
app := ui.NewCliApp(ranker, storage)
switch config.Command {
case config.ADD_COMMAND:
app.AddAction(config.AddItem)
case config.LIST_COMMAND:
app.ListAction()
case config.DELETE_COMMAND:
app.DeleteAction(config.DeleteItemNumber)
default:
fmt.Printf("Config has bad command %s!", config.Command)
}
app.SaveAction()
}
}