-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
41 lines (33 loc) · 918 Bytes
/
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
package main
import (
"os"
"github.com/KyleBanks/commuter/cli"
"github.com/KyleBanks/commuter/cmd"
"github.com/KyleBanks/go-kit/storage"
)
const (
configurationFileName string = "config.json"
configurationDirName string = "commuter"
)
func main() {
out := cli.NewStdout()
store := storage.NewFileStore(configurationDirName, configurationFileName)
conf := cmd.NewConfiguration(store)
parser := cli.NewArgParser(os.Args[1:])
r, err := parser.Parse(conf, store)
if err != nil {
panic(err)
}
exec(out, conf, r)
}
// exec validates and executes a Runner with the Indicator and Configuration provided.
func exec(i cmd.Indicator, c *cmd.Configuration, r cmd.RunnerValidator) {
if err := r.Validate(c); err != nil {
i.Indicate("Invalid command: %v", r)
i.Indicate("Error: %v", err)
}
if err := r.Run(c, i); err != nil {
i.Indicate("Command Failed: %v", r)
i.Indicate("Error: %v", err)
}
}